A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: If, Else help

  1. #1
    Senior Member
    Join Date
    May 2006
    Posts
    119

    If, Else help

    this is a second posting if anyone here is getting dejavu. I made a mistake in the title of the old one.....sorry
    so anyways
    I have a faily simple question. I want to know how to write an "If Else" for a mouse click. I can write an hittest, but im not to sure of the mouse clicks. this is what I want to make shorter
    ---------------------------------------------
    _root.q1_immark.onRelease = function (){
    _root.gotoAndPlay("Q2_Good");

    }
    _root.q1_nicetomeetyou.onRelease = function (){
    _root.gotoAndPlay("Q2_Bad");
    }

    _root.q1_wherearewe.onRelease = function (){
    _root.gotoAndPlay("Q2_Bad");
    }

    since two actions have the same outcome, I figure I can consolodate some code.
    also can I declare MCs as clickable buttons in a single line?


    thanks in advance

    Mark

  2. #2
    Amazed and Amused Mazoonist's Avatar
    Join Date
    Mar 2006
    Location
    Northern California
    Posts
    201
    Hey, Mark,

    I'm not really sure what you are wanting to achieve with an if-else block. Could you explain?

    You can combine two functions with the same outcome like this (using your example):
    Code:
    _root.q1_nicetomeetyou.onRelease = _root.q1_wherearewe.onRelease = function (){
        _root.gotoAndPlay("Q2_Bad");
    }
    To write something all on one line, and using your example(s) again:
    Code:
    _root.q1_immark.onRelease = function (){_root.gotoAndPlay("Q2_Good");}
    If there's more than one command within the curly braces, separate them with semi-colons. While this can be done, the question is whether it should be done, as it makes it a lot harder to read, and harder to edit later. Better to put commands on their own lines, and use indenting for blocks. Also, performance-wise, you don't gain anything by writing it all on one line. Since there's no advantage, why do it?

  3. #3
    Senior Member
    Join Date
    May 2006
    Posts
    119
    Thanks, I will explain a little more in detail. Im wondering if I can turn this into an IF statement
    this is a vauge though of it

    if (buttonA.isClicked){
    gotoAndPlay(X);
    }

    else (!buttonA.isClicked){
    gotoAndPlay(Y);
    }
    I am giving the user a choice of 3 answers, one advances the play head to a correct response sequence, the other 2 answers direct you to a incorrect response sequence. so I figures I would wrap up this

    _root.q1_nicetomeetyou.onRelease = function (){
    _root.gotoAndPlay("Q2_Bad");
    }

    _root.q1_wherearewe.onRelease = function (){
    _root.gotoAndPlay("Q2_Bad");
    }

    into the "ELSE" part of the statement to save me some typing (there will be many of these questions.

    any thoughts?

    Mark

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    119
    its more that I want to know how to write an IF, ELSE for mouse clicks now, the suggetion you gave will work.

    Cheers

  5. #5
    Amazed and Amused Mazoonist's Avatar
    Join Date
    Mar 2006
    Location
    Northern California
    Posts
    201
    There's no need to write an IF ELSE for mouse clicks. If you've got, say 10 buttons (or whatever), and separate ON RELEASE handlers written for all those buttons, then each button will fire its own event handler, so there's no need to write code to detect which button was pressed.

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