A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Very quick if statement question.

  1. #1
    Junior Member
    Join Date
    Apr 2003
    Location
    UK
    Posts
    14

    Very quick if statement question.

    Hi I have a very quick question about writing if statements.

    When the user clicks a button I want h1 and h2 to either appear or dissapear depending on their current state, I can get just one to work (i.e. h1 on its own) but I don't know the correct syntax for two or even three variables. I've shown my code below, as you can see I thought a comma might work to separate the values but it doesn't.

    code:

    on (release) {
    if (h1,h2._visible) {
    h1,h2._visible = false;
    } else {
    h1,h2._visible = true;
    }
    }

    Last edited by jbum; 10-01-2004 at 01:57 PM.

  2. #2
    Senior Member
    Join Date
    Jul 2004
    Location
    In a box outside of Safeway
    Posts
    201
    code:

    on (release) {
    if (h1._visibility && h2._visibility) {
    h1._visibility, h2._visibility = false;
    } else {
    h1._visibility, h2._visibility = true;
    }
    }

    Last edited by jbum; 10-01-2004 at 01:57 PM.
    If computer games affected us, would I not be running into walls popping strange yellow pills and listening to repetitive music?

  3. #3
    Junior Member
    Join Date
    Apr 2003
    Location
    UK
    Posts
    14
    That doesn't work mate. I assume you meant _visible instead of _visibility. Anyway I tried both methods and neither worked. Any more ideas on this one, I know its only a small thing, but I don't know the proper syntax in ActionScript.

  4. #4
    Senior Member
    Join Date
    Jul 2004
    Location
    In a box outside of Safeway
    Posts
    201
    code:

    on (release) {
    if (h1._visible == true && h2._visible == true) {
    h1._visible, h2._visible = false;
    } else {
    h1._visible, h2._visible = true;
    }
    }



    EDIT: Edited some of the posts in this thread to use as tags - jbum
    Last edited by jbum; 10-01-2004 at 01:58 PM.
    If computer games affected us, would I not be running into walls popping strange yellow pills and listening to repetitive music?

  5. #5
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    In my version of flash (MX 2004) the following code does not work:

    code:

    // BROKEN!!
    x,y = 5;
    trace(x);
    trace(y);



    If you do the above, y will be equal to 5, but x will be undefined. This implies that the example shown above, also using a comma, will also not work.

    The following does work, however:

    code:

    x = y = 5;
    trace(x);
    trace(y);



    As does this:

    code:

    x = 5;
    y = 5;
    trace(x);
    trace(y);



    Personally, I would go with that last method - it's clearest. However, if you really want to save typing a few characters, at the expense of a little readability, by all means try this:

    code:

    on (release) {
    if (h1._visible == true && h2._visible == true) {
    h1._visible = h2._visible = false;
    } else {
    h1._visible = h2._visible = true;
    }
    }


  6. #6
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    if all you are doing is toggling the visibility then there is no need for an if statement anyway...
    code:

    on(release){
    h1._visible = h2._visible = !h1._visible;
    }

    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

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