3 Replies Latest reply on Jun 17, 2009 2:02 PM by AllanCaveNZ

    FrameLabel vs .currentLabel vs currentFrame

    AllanCaveNZ

      Hey people,

       

      Quick question, i've run into an issue in AS3 where I can't seem to accurately acquire the frame number in a movieclip, my script is on the root/stage level and references my movieclip. I've tried using FrameLabel and currentFrame instead of how it is below where I'm making a variable using the currentLabel query and they all seem to give an incorrect answer when I get past the first frame, meaning it jumps back to frame 1. I figure there's some fundemental error in the terms I'm using but i'm not sure what other options I have. My script is below, any help or ideas would be great. Thanks!

       

       

      next_btn.addEventListener(MouseEvent.CLICK, onwards);

      function onwards(event:MouseEvent):void {

       

      if (framenum < 5) {

      pic.gotoAndPlay(nextFrame);

      } else {

      pic.gotoAndPlay(1);

      }

      }

       

      var framenum = pic.currentLabel;

       

       

       

       

      Thanks,

      Allan

        • 1. Re: FrameLabel vs .currentLabel vs currentFrame
          robdillon Most Valuable Participant

          You have a couple of fundamental problems with your code.

           

          First, you are defining the variable "framenum" outside of the function:

          var framenum = pic.currentLabel;

           

          Normally this is fine, and as it is this will work to give an initial value to the variable. However, you want this value to be updated when the function "onward" is called by the mouse click. So, a better place to put this definition is inside the function. That way, the value is updated every time the mouse is clicked and you will get the currentLabel, or currentFrame value that you want.

           

          Second, you are telling the playback head to move to a new frame that is undefined, as far as I can see:

          pic.gotoAndPlay(nextFrame);

           

          You are using a variable named "nextFrame" to tell the playback head where to move to. This is undefined and so will never execute correctly. I'm guessing that what you really want to do is to move to the next frame in the clip "pic". If that's the case then you actually want to use the method nextFrame(). If that's the case then you want to use:

          pic.nextFrame();

           

          Try these two changes and see if you get what you want.

          • 2. Re: FrameLabel vs .currentLabel vs currentFrame
            Ned Murphy Adobe Community Professional & MVP

            Try:

             

            next_btn.addEventListener(MouseEvent.CLICK, onwards);

             

            function onwards(event:MouseEvent):void {

                 if (pic.currentFrame < 5) {

                      pic.gotoAndPlay(pic.currentFrame+1);

                 } else {

                      pic.gotoAndPlay(1);

                 }

            }

             

            and get rid of the last line you had.

            • 3. Re: FrameLabel vs .currentLabel vs currentFrame
              AllanCaveNZ Level 1

              cheers guys, i had tried including the variable in the function at one stage but still seemed to be doing strange things, but will remember that in future. the line "pic.gotoAndPlay(pic.currentFrame+1)" seems to work a dime.  I'll have to pick up a hand book for AS3 and learn the foundations, i've tripped my way through learning out of tutorials and other peoples scripts but I've probably missed a few fundamentals along the way.

               

              Thanks again!

              Allan