A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: simple if statement

  1. #1

    simple if statement

    I made 2 variables at a certain point in the timeline
    var photo1=1
    var photo2=2

    Then after a button is clicked:
    if (photo1=1) {
    _parent.photo1.gotoAndPlay("reduce");
    }

    That works fine, but the moment I add the second part:
    if (photo1=1) {
    _parent.photo1.gotoAndPlay("reduce");
    }
    if (photo2=2) {
    _parent.photo2.gotoAndPlay("reduce");
    }

    it all breaks. Why is that? I have tried using "==" too and that didnt help.
    Thanks
    Dan

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    if (photo1==1)
    is the (only) correct syntax

    gparis

  3. #3
    Dont know what I could be doing wrong. I attached the fla. I just need it to check if any other images (I used numbers here) are open when clicked and to close them automatically. thanks
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    If you look into your ouput for variables, you'll find this:
    _level0.instance1.photo1.photo1 which is the full path of the variable photo1.

    So not only should you change the equality sign to a double in the if statements, but you should also give an instance name to that 'instance1' (default name used by flash for symbols that miss an instance name) and when trying to reference the variable 'photo1' make sure to use either the correct relative path or the correct absolute path.

    gparis
    Last edited by gparis; 02-14-2007 at 05:13 PM.

  5. #5
    The instance name is photo1? Where else is there an option to give another instance name?

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    no. the variable name is "photo1" and the MovieClip that it's declared in, has no instance name.

    gparis

  7. #7
    Ah, I see. That didnt help though. I named it "photos" and used:if (_root.photos.photo1==1) {
    _root.photos.photo1.gotoAndPlay("reduce");
    }
    if (_root.photos.photo1==2) {
    _root.photos.photo2.gotoAndPlay("reduce");
    }

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