PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How can I do an if else?
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: How can I do an if else?

  1. #1
    Senior Member
    Join Date
    Dec 2004
    Posts
    459

    How can I do an if else?

    Hey, hope you can help me.

    I have two invisible buttons. One brings up on movie clip, the other brings up another. If either of these invisible buttons are clicked when the other movie clip is on it plays over the other movie clip. I want to make it so if either of the movie clip is playing, when the other invisible button is clicked it will make the other movie clip go to a frame where it is not played anymore. Wheewww. Hope that's clear.
    Let me try again.
    Inv 1 button plays MC 1. Inv 2 plays MC 2. If I want MC2 to end when Inv 1 button is clicked. I want MC 1 to close when Inv 2 Button is clicked.

    Here is the code I have so far:
    Actionscript Code:
    on (rollOver) {
        this.boxfill.gotoAndPlay("startboxfill");
        this.blackout.gotoAndPlay("startblackout");
        this.resumetext.gotoAndPlay("startresume");
       
       
    }
    on (rollOut) {
        this.boxfill.gotoAndPlay("stopboxfill");
        this.resumetext.gotoAndPlay("endresume");
    }

    on(press){
        this.resumetext.gotoAndPlay("downresume");
       
       
    }
    on (release){
        this.resume.gotoAndPlay("startresume");
        this.stripout.gotoAndPlay("startdark");
        //this.resume.gotoAndPlay("upagain");
       
    }

    /////// Try the if else statement //////////

    if (   ){
       
       
       
    } else if (      ){
       
       
       
    }

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    something liek this you mean?

    *tip: is not recommended putting code ON object/movieClip like you are.. its better to put all code in the FRAME/timline

    the top vars would go in the MAIN timeline


    var isPlaying:Boolean = false;
    var targetClip:MovieClip;

    on (rollOver) {
    this.boxfill.gotoAndPlay("startboxfill");
    this.blackout.gotoAndPlay("startblackout");
    this.resumetext.gotoAndPlay("startresume");


    }
    on (rollOut) {
    this.boxfill.gotoAndPlay("stopboxfill");
    this.resumetext.gotoAndPlay("endresume");
    }

    on(press){
    this.resumetext.gotoAndPlay("downresume");


    }
    on (release){
    if(_parent.isPlaying == true){
    _parent.targetClip.gotoAndStop("endFrame");
    _parent.targetClip = this;
    }else{
    _parent.isPlaying = true;
    _parent.targetClip = this;
    }
    this.resume.gotoAndPlay("startresume");
    this.stripout.gotoAndPlay("startdark");
    //this.resume.gotoAndPlay("upagain");
    }

  3. #3
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Silly me. All I had to do was make each MC go to a frame and stop on the onPress function.

    on (rollOver) {
    this.boxfill.gotoAndPlay("startboxfill");
    this.blackout.gotoAndPlay("startblackout");
    this.resumetext.gotoAndPlay("startresume");


    }
    on (rollOut) {
    this.boxfill.gotoAndPlay("stopboxfill");
    this.resumetext.gotoAndPlay("endresume");
    }

    on(press){
    this.resumetext.gotoAndPlay("downresume");


    }
    on (release){
    this.resume.gotoAndPlay("startresume");
    this.stripout.gotoAndPlay("startdark");
    this.interview.gotoAndStop("stopInterview");
    //this.resume.gotoAndPlay("upagain");

    }













    Quote Originally Posted by whispers View Post
    *tip: is not recommended putting code ON object/movieClip like you are.. its better to put all code in the FRAME/timline

    the top vars would go in the MAIN timeline


    Thank you. I will try the code and let you know what happens.
    I'm not sure I understand what you mean by the above quote.

    It's not working.

    I get these errors:
    Statement must appear within on handler
    Operator '=' must be followed by an operand
    Statement block must be terminated by '}'
    Let me try to fix these.

    Here is the code: var isPlaying:Boolean = false
    var targetClip:MovieClip



    on (rollOver) {
    this.boxfill.gotoAndPlay("startboxfill");
    this.blackout.gotoAndPlay("startblackout");
    this.resumetext.gotoAndPlay("startresume");


    }
    on (rollOut) {
    this.boxfill.gotoAndPlay("stopboxfill");
    this.resumetext.gotoAndPlay("endresume");
    }

    on(press){
    this.resumetext.gotoAndPlay("downresume");


    }
    on (release){
    if(_parent.isPlaying = = true){
    _parent.targetClip.gotoAndStop("endFrame");
    _parent.targetClip = this;
    }else{
    _parent.isPlaying = true;
    _parent.targetClip = this;



    this.resume.gotoAndPlay("startresume");
    this.stripout.gotoAndPlay("startdark");

    }

    Last edited by An Artist; 08-05-2010 at 09:46 AM. Reason: I found the solution

  4. #4
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    sorry.. let me try to explain..or be a bit more clear. =)

    first there is what is called FRAME or TIME LINE code.. (which is recommended/preferred)

    and there is 'object code' this is NOT OOP or Object Oriented Programing.. I mean you select the button, movieclip..(whatever) on the stage.. and paste the actions on that instance. Which is what you are doing.

    the first is preferred because all code is organized, and easy to locate and hence work with.. Instead of trying to guess where code is applied and on what objects on your stage..etc..


    when using FRAME code..the syntax is a BIT different.. but once you get used to it.. you will never go back (I promise).


    Every 'object' (movieClip, button, text field..etc) is really an 'object'.. or more specifically an 'instance' of an object...

    and shoudl have its very own INSTANCE NAME.

    movieClip__mc , nameText_txt... whatever..

    by giving your objects an instance name you can now target,,and control/manipulate them with code.


    Here is example for you to try.. very simple..

    new .fla

    draw a square on your stage..

    select it, and convert it to a movieClip.

    give it instance name of "clip_1"


    now...click/select FRAME 1 in your MAIN time line.

    put this code there:

    clip_1.onPress = function(){
    this._alpha = 25;
    }


    thats it..

    that is the same as:

    on(press){
    this._alpha = 25;
    }

    but its alot cleaner, centralized places to edit all code..and more professional by naming your objects (always)..and using a more intuitive coding 'pattern'..


    of course you make or copy a new movieClip on the stage... change the INSTANCE NAME..lets make it clip_2

    and you can then do:

    clip_1.onPress = function(){
    this._alpha = 25;
    }
    clip_2.onPress = function(){
    this._xscale = 225;
    }

    very easy.. you have code for both objects in the MAIN time line in FRAME 1 easy to go back and edit whatever you need.

  5. #5
    Junior Member
    Join Date
    Sep 2007
    Posts
    23
    Where you put your code is dependant on what it will be used for.
    I never put all my code in as files/frames.. If I have a button for example which I will never have to change, it's preferable to put the code in there if you know you're never going to need to modify it.

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    You cannot code ON objects anymore in the latest version of flash/as3. So, if you plan to still write code in the future, you really should get rid of that bad habit. If coding is just a hobby, then by any means, do what you want ;-)

    gparis

  7. #7
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Quote Originally Posted by lp9sc View Post
    Where you put your code is dependant on what it will be used for.
    I never put all my code in as files/frames.. If I have a button for example which I will never have to change, it's preferable to put the code in there if you know you're never going to need to modify it.
    Sorry.. thats just NOT true.

    just because you 'can' doesnt mean you SHOULD.


    And its not a good idea to recommend this to people.

    tell me why..or better yet convince me why its better to put code ON a button..instead of the frame the button is on?

    in a frame you always know wher the code is.

    on a button.. how do you know ther is even ANY code? how do you know what button out of say 20 is the one you need to edit? click on each one to see the code.?

    It makes the most sense to put all your code in one centralized place..and have it delegate its actions/control over everything on the stage.
    (central command)

    Now using your 'example'.. if you worked or created a project at a company BEFORE I was hired..and I had to try and work on your un-finished projects.. it would be a COMPLETE nightmare.


    Also..as stated.. you not even allowed to do that anymore in newer versions of Flash.

  8. #8
    Junior Member
    Join Date
    Sep 2007
    Posts
    23
    Quote Originally Posted by whispers View Post
    And its not a good idea to recommend this to people.

    in a frame you always know wher the code is.

    on a button.. how do you know ther is even ANY code? how do you know what button out of say 20 is the one you need to edit? click on each one to see the code.?

    It makes the most sense to put all your code in one centralized place..and have it delegate its actions/control over everything on the stage.
    (central command)

    Now using your 'example'.. if you worked or created a project at a company BEFORE I was hired..and I had to try and work on your un-finished projects.. it would be a COMPLETE nightmare.

    Also..as stated.. you not even allowed to do that anymore in newer versions of Flash.
    Most of your post goes back to what I said:
    Where you put your code is dependant on what it will be used for.

    Of course you would have to care about the structure of your code if you were collaborating on a project with other people, if it's for personal use then it really doesn't matter if other people will know or not, as long as you yourself know.

    Good example of where to use it:
    On a button for a login page, you're only going to have a few instances on that one page so it wont be hard to find. (Personal use of course)

    I'd also prefer to just click a button to edit my code rather than shuffle through thousands of lines on a single frame.. again, as long as I can find it.

Tags for this Thread

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