[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 704
  • Last Modified:

Playing certain frames in AS3.0

Timeline scripting

I have a movie clip that is 30 frames long. It is a clip of tab menu sliding out, and then back in again. However, I want it to stop when it is out, until some logic makes it go back in again. It's easy to do if I add a stop(); on frame 15, but I want all my actionscript to be on frame 1.

How can I tell the animation to just play to frame 15 and then stop?

Also, how can I get the information about which frame the playhead is on in a movie clip instance?
0
Jason210
Asked:
Jason210
  • 2
1 Solution
 
H01Commented:
Hi Jason210

Lets say you have a movie clip name Test:

for the movie clip to play until frame 15 you can create a function to loop until it reach frame 15 and stop for example :

GoToFrame(15) <--- will loop and play until frame 15

function GoToFrame(Frame:int){
      Test.addEventListener(Event.ENTER_FRAME,LoopToFrame)
      
      function LoopToFrame(){
         if(Test.currentFrame < 15){
               Test.gotoAndStop(Test.currentFrame + 1)
         }else{
               Test.removeEventListener(Event.ENTER_FRAME,LoopToFrame)
               trace(Test.currentFrame) <--------- Will tell you which frame it stop at.
         }
      }
}
0
 
Jason210Author Commented:
Thanks. Some stuff to look at there. ENTER_FRAME is new to me. currentFrame is also handy.
Now, just a couple of questions regarding your suggestion.
Firstly, it seems the animation of the timeline is controlled by this statement being in a loop...
gotoAndStop(Test.currentFrame+1)
The only thing that worries me here is that it seems this is no control over the frame rate, that it will just whizz through this as fast the processor will allow?
Second question. Why do you remove the event listener? I have never done this before. Is it important to do?
Thanks for your patience.
 
0
 
H01Commented:
Hi Jason210

ENTER FRAME is control by the frame rate you set, the faster the fps you set the faster the code execute (the faster the loop will run), it is not base on processor speed.

In the end I remove the listener is to stop the code from keep on Looping because once you add listener on ENTER_FRAME the code will keep on execute base on the fps you set and as long as the movie is running so you have to remove the listener in the end.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now