7 Replies Latest reply on Jun 13, 2007 2:12 PM by kglad

    Variable in a button

    Geisen Level 1
      I'm not a developer, I'm a mere designer so please bear with me.

      I'm trying to build an interactive presentation with an autorun.

      To accomplish this, I start the flash movie with a frame action assigning the variable "p" a value of "0"

      var p
      p = 0;


      Then I use a button with a keypress to play a movie clip. (This works fine)


      on (keyPress "a") {
      tellTarget ("_root.autorunon") {
      play();
      }

      }


      In the movie clip' "_root.autoruinon"s timeline, I reassign the value of "p" to "1"


      var p
      p = 1;


      And the later in the clip I tell the play-head to make a choice. If "a" was depressed, "p" would equal "1" and the movie clip would go to a specific marker and play. Otherwise, If "a" wasn't depressed, "p" would equal "0" (because of the frame action) and the play-head would go to another specified marker.

      if (p = 1){
      gotoAndPlay("b");
      }
      else if (p = 0){
      gotoAndStop("brand buttons");
      }


      Well, unfortunately, it doesn't work and I have no idea why. When the play head gets there, it proceeds as if "p" equals "1" regardless of whether or not I've depressed the "a" key.

      Any help on this would be most appreciated.

      Thanks!

        • 1. Re: Variable in a button
          kglad Adobe Community Professional & MVP
          use double equal (==) for comparison testing. otherwise, you're using the assignment operator.

          also, you may have a path problem. the p=0 statement may not be on the same timeline as the p=1 statement. if they are both on the _root.autoruinon [sic?] timeline, there won't be a path problem. otherwise, there will be.
          • 2. Variable in a button
            Geisen Level 1
            quote:

            Originally posted by: kglad
            use double equal (==) for comparison testing. otherwise, you're using the assignment operator.

            also, you may have a path problem. the p=0 statement may not be on the same timeline as the p=1 statement. if they are both on the _root.autoruinon [sic?] timeline, there won't be a path problem. otherwise, there will be.


            Gotcha on comparison vs. assignment. I told you I wasn't a developer.

            I originally had the p=1 assignment in the "keypress" action for the button and it didn't work then. The button was on the main timeline (and I did have the double equals in the comparison at the time)

            Is there a way for me to assign p=1 inside a movie clip and have it somehow apply to the root timeline so that it will correspond with frame actions that need to call it on the main timeline?

            EDIT::::::::::

            It works fine if I put the assignment in a frame so that it assigns when the playhead rolls into it:

            var p
            p = 1

            I guess I just need to figure out how to get it to make the assignment in a movie clip and have it correspond to the root timeline so that the frame action on the root timeline picks it up.

            Please give me the syntax if you could. I'm not too good with all that jazz.

            • 3. Re: Variable in a button
              kglad Adobe Community Professional & MVP
              if you prefix p with _root, the variable that flash checks will be the same no matter where p is located (in you _level0 swf):

              • 4. Variable in a button
                Geisen Level 1
                It's giving me a syntax error for:
                • 5. Re: Variable in a button
                  kglad Adobe Community Professional & MVP
                  don't prefix with var (or anything else). there's no need and no benefit to declaring variables (or other objects) in as2.
                  • 6. Re: Variable in a button
                    Geisen Level 1
                    Whew.

                    You're the GREATEST!

                    Thank heaps. Worked like a charm!

                    I'll probably be back.
                    • 7. Re: Variable in a button
                      kglad Adobe Community Professional & MVP
                      you're welcome.