A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [F8] ActionScript help

  1. #1
    Banned
    Join Date
    Jul 2007
    Posts
    7

    [F8] ActionScript help

    Hello

    I thought I should post this here instead of the ActionScript-boards.

    I'm making an adventure game and I'm trying to find out how to make a button with a command like "if been in frame X goto frame Y, if not been in frame X goto frame Z". Is this possible?

    Here's an example how it would work in my game:

    Guy goes to a bar and receives a beer (frame X)
    A person asks the guy for a beer, if the guy has a beer the person gives him a clue (frame Y), if the guy doesn't have a beer the person doesn't tell the guy anything (frame Z).

    I hope you understand what I'm trying to do.

    EDIT: Also, do you know any good IRC-channels/servers for asking these types of questions?
    Last edited by MrXX; 07-09-2007 at 07:15 AM.

  2. #2
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Please try this code which is working for me.
    Code:
    var a=_currentframe;
    var fx=2;//say.
    var fy=3;//say.
    var fz=4;//say.
    if(a==fx){
    gotoAndStop(fy);
    }else{
    gotoAndStop(fz);
    }
    trace(_currentframe);
    stop();
    <signature removed by admin>

  3. #3
    Banned
    Join Date
    Jul 2007
    Posts
    7
    I couldn't get it to work, here's my .fla:
    http://www.wikiupload.com/download_page.php?id=174588
    (I'm trying to force the user to click the red circle first before clicking the purple one, if the user clicks purple one before red he gets a stop-sign, if he has clicked red before purple he receives a green text)

    New question: Let's say my guy goes into that bar frame and receives a beer. I want a beer icon to appear to bottom of the screen in every frame. How do I do that?
    Last edited by MrXX; 07-09-2007 at 08:09 AM.

  4. #4
    Senior Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    132
    hey there

    first of all I couldnt download your .fla file, but anyway, for your first question regarding X, Y, Z frame jumps what EagerBeaver said is somehow correct, the idea is to use the movie clip _currentframe property to find out where the current position is and using an if statement go to your desired location.

    your second question about displaying the beer icon on the screen, just create a beer movie clip and put it on a layer and give it an instance name, then create a variable in your action script called bBeer and set it to false. then create a function that checks if the beer is collected by the user.
    let me try showing some AS:

    Code:
    var bBeer:Boolean = false;
    
    function checkBeer(bBeer){
        if(bBeer == true){
           Beer_mc._visible = true;
        }else{
           Beer_mc._visible = false;
        }
    }
    create this on your main timeline, and preferably on frame 1 then all you need to do is just call the function whenever you need to change the state; for instance, first call it on its frame 1

    Code:
    checkBeer(false);
    and call it again when the user recieves the beer
    Code:
    checkBeer(true);
    I hope this helps, i know it might be a bit confusing but its much better to learn than just copy some code

    please ask any questions you might have!

    Ameretat
    Adobe Certified Associate in Rich Media Communication Flash CS3

    My Company: Helix Creative My Main Project: CreativeChain

  5. #5
    Banned
    Join Date
    Jul 2007
    Posts
    7
    To Ameretat:

    Thank you for your help, I understand that code and the purpose of it, but I have few questions:

    -What should my beer movie clip/instance name be? Beer, bBeer, Beer_mc?!

    -Where do I put this code, 1st frame, Beer movie clip, inventory layer?
    Code:
    var bBeer:Boolean = false;
    
    function checkBeer(bBeer){
        if(bBeer == true){
           Beer_mc._visible = true;
        }else{
           Beer_mc._visible = false;
        }
    }
    -Do I put the checks to frames or buttons?

    EDIT: oh, and here's a new download link http://tiny url.com/345zl7 (remove space). I have tried to combine both of my problems to this single .fla
    Last edited by MrXX; 07-09-2007 at 09:52 AM. Reason: new link

  6. #6
    Banned
    Join Date
    Jul 2007
    Posts
    7
    I got the beer thing working! Now is it possible to make buttons, instead of movie clips, disappear? That way I wouldn't need the X,Y,Z frame checking.

  7. #7
    Senior Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    132
    good that you got it working.

    yes, you can also make buttons disappear, both buttons and movie clips support a properties called _visible which controls the visibility of the object at run time. so you can easily reference to a button and set its _visibile to false or true.

    Hope that helps

    Ameretat
    Adobe Certified Associate in Rich Media Communication Flash CS3

    My Company: Helix Creative My Main Project: CreativeChain

  8. #8
    Banned
    Join Date
    Jul 2007
    Posts
    7
    Quote Originally Posted by Ameretat
    yes, you can also make buttons disappear, both buttons and movie clips support a properties called _visible which controls the visibility of the object at run time. so you can easily reference to a button and set its _visibile to false or true.
    Thanks for the help again, but I can't seem to get this to work.

    I have a button named 'Getbeer' and a mc called 'Beer'

    This is in my frame 1
    Code:
    stop();
    var cGetbeer:Boolean = false;
    
    function checkGetbeer(cGetbeer){
        if(cGetbeer == true){
    	   Getbeer._visible = false;
        }else{
    	   Getbeer._visible = true;
        }
    }
    
    var cBeer:Boolean = false;
    
    function checkBeer(cBeer){
        if(cBeer == true){
           Beer._visible = true;
        }else{
           Beer._visible = false;
        }
    }
    This in beer getting frame
    Code:
    checkBeer(true);
    checkGetbeer(true);
    This in giving away beer frame
    Code:
    checkBeer(false);
    checkGetbeer(false);
    The beer dis/appears fine but the Getbeer button is visible all the time.

  9. #9
    Learning Flash yow's Avatar
    Join Date
    Jun 2007
    Location
    melbourne
    Posts
    110
    I suggest separating setting of the flag and the visibility, because it seems that changing the visibility only works when that mc is being displayed (please correct me if this is wrong). This is a problem for the button, because it's only present in one frame.

    eg (just for the button)

    Code:
    var cGetbeer:Boolean = false;
    
    function checkGetbeer(){
        if(cGetbeer == true){
    	   Getbeer._visible = false;
        }else{
    	   Getbeer._visible = true;
        }
    }
    In all frames with the button in it, use this:
    Code:
    checkGetbeer();
    To change the state (eg. I guess when you've already got the beer, and don't want to show the button anymore):
    Code:
    cGetbeer = false;
    The attachment is based on your previous fla (I made the instance name of the button be "Beer2_mc", because it didn't seem to have one...).

    HTH
    Brendan
    code tested in Flash Basic 8 (AS2), Windows XP

  10. #10
    Senior Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    132
    yes, one thing to remember when coding in Flash is that, each keyframe presents a new instance of the object, so unless you copy the key frames over, you will have to add the code to the new keyframe.


    Ameretat
    Adobe Certified Associate in Rich Media Communication Flash CS3

    My Company: Helix Creative My Main Project: CreativeChain

  11. #11
    Banned
    Join Date
    Jul 2007
    Posts
    7
    Thank you yow and Ameretat, that worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center