7 Replies Latest reply on Nov 16, 2007 10:13 PM by kglad

    actionscript 2  question

    jzauner
      I have about ten days of actionscript experience. I'm taking a break from the book and trying a few things on my own.

      Anyway, I'm trying to set a boolean variable to true from inside a movie so that it effects the actionscript on the _root frame1.

      Specifically, when the movie comes to it's last frame, I want the variable "frame12" to be true and "pass(?)" this information back to the main timeline and use it to start another movie.

      Right now I've declared my variable on the _root like this:

      var frame12:Boolean=false

      In the last frame of the movie I've put this:

      frame12=true

      I'm going to put all the code I've written thus far. Any suggestions or comments are appreciated. Like I said, it's not a "project", just some experimenting.

      On frame 1 of the _root:


      On the last frame of the movie:

        • 1. Re: actionscript 2  question
          kglad Adobe Community Professional & MVP
          your frame12 variable on your movieclip's timeline is not the same as frame12 on your main or _root timeline. the situation is analogous to a file named text.txt in one directory and another file named text.txt in a different directory. they are different files despite the same names because their paths are different. and changing one does not affect the other.

          just like the file analogy, there's a path that's used to access your variables. instead of backslashes to designate paths flash uses the dot (.) operator. so, from within any movieclip's timeline

          _root.frame12

          references the frame12 variable on the _root timeline. and from your _root timeline you can reference your movieclip's (with instance name, say mc) frame12 variable by using

          mc.frame12.
          • 2. Re: actionscript 2  question
            Flash-Tastic
            --kglad
            Thanx for that info, at one point recently i was wondering that exact thing. This is great info.
            Would this work with functions too?
            could I have a function on _root timeline, and call it from nested movieClips?
            or does calling functions require other things?

            P.S. sorry to just barge in on your topic jzauner. but good luck with your learning. Flash is GREAT =)
            • 3. Re: actionscript 2  question
              kglad Adobe Community Professional & MVP
              it works exactly the same for functions. the only issue is timing.

              a function on the _root timeline (in a frame that's played) is defined and ready for reference from any movieclip by using:



              • 4. Re: actionscript 2  question
                Flash-Tastic Level 1
                what exactly is the timing issue?

                do you meant about the frame where the function is located?
                eg.. _root playhead is on frame 5.
                function is located on frame 10.

                Is this what you are referring to?
                • 5. Re: actionscript 2  question
                  jzauner Level 1
                  Thanks, that's helped. Now the variable frame12 is true, but for some reason it becomes true before it gets to the last frame where the code is: _root.frame12=true;

                  Here's some more detail: I have two instances of the same movie. When the user releases myMovie1_mc.button1 of myMovie1_mc it makes myMovie2_mc visible and plays the movie starting at frame-1 to frame-12 where it stops. When the user releases myMovie2_mc.button1 of myMovie2_mc I would like it -- myMovie2_mc -- to play to the last frame where _root.frame12=true would tell myMovie1_mc to THEN play from frame-12 to the finish. The effect would be, myMovie2_mc would be come invisible and THEN myMovie2_mc would be come invisible.

                  But this doesn't happen.

                  Instead, when I release myMovie2_mc.button1 of myMovie2_mc, both movies start playing from frame-12 before the variable frame12 has been turned to true.

                  Here's the code that applies:

                  ...
                  myMovie1_mc.button1_mc.onRelease = function() {
                  myMovie2_mc.button1_mc.buttonText_txt = "parent";
                  myMovie2_mc.gotoAndPlay(1);
                  myMovie2_mc._visible = true;
                  myMovie2_mc.button1_mc.onRelease = function() {
                  myMovie2_mc.gotoAndPlay(12);
                  //a test to make sure the button works
                  _root.gotoAndPlay("parent");
                  //should make myMovie1_mc play and does just not when I expected
                  if (frame12=true){
                  myMovie1_mc.gotoAndPlay(12);
                  }...
                  • 6. Re: actionscript 2  question
                    jzauner Level 1
                    bump
                    • 7. Re: actionscript 2  question
                      kglad Adobe Community Professional & MVP
                      no, the timing issue is having a function in the first frame of a movieclip and having function call in the same frame where the movieclip is instantiated. the function isn't defined when it's called.

                      jzauner i have no idea what you're trying to do by having one onRelease defined in another movieclip's onRelease handler.

                      if you want one button handler to activate another button, use the enabled property of movieclips and buttons.