FORUMS: list search recent posts

Control timeline AS3

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jessica Chapman
Control timeline AS3
on Oct 31, 2010 at 11:58:20 am

Hi there,

I am new to coding in AS3, and I was just wanting to know how I would go about controlling the timeline with actionscript (for example after 5 seconds, frame 1 goes to frame 2)? I want to minimise the amount of frames in my swf. :)


Any help is very much appreciated!

Cheers,
Jess


Return to posts index

Brodd Nesset
Re: Control timeline AS3
on Oct 31, 2010 at 5:54:39 pm

Write once, use whenever. In the first frame:

function myPause(secs:Number) {
stop();
var myTimer:Timer = new Timer(secs * 1000, 1);
myTimer.addEventListener(TimerEvent.TIMER, resume);
myTimer.start();
function resume(e:TimerEvent) {
play();
myTimer.removeEventListener(TimerEvent.TIMER, resume);
}
}


Then, anywhere in the Timeline you want to pause a bit:

myPause(1); //For a once second pause
myPause(4.2) //For a four point two seconds long pause

...and so on.

You can rename 'myPause' to something different, as long as it's not a reserved name of course. And you can put it in a Document Class or other external class file for ultimate re-usability.
This is a very simple but basic Timer, which will serve in most cases.



Not everything that can be counted counts, and not everything that counts can be counted.



Return to posts index

Jessica Chapman
Re: Control timeline AS3
on Nov 1, 2010 at 2:25:26 am

Thank you very much for the helpful reply! :)

I was just wondering how I go about defining each frame in the actionscript with the accompanying pause time (myPause)? ^_^;;


Thank you!
Jess


Return to posts index


Brodd Nesset
Re: Control timeline AS3
on Nov 1, 2010 at 9:27:51 am

1. This script is intended for pausing the Timeline 'horizontically' if you wish. To make a pause in frame 5, create a keyframe in your script layer and write myPause(2); for a two second halt there. That's all there is to it. A five second pause in frame 11: write myPause(5); in frame 11 and so on.
This functionlity should have been built in to Flash, but is not, somehow. Well, now you have it.

Note that this doesn't affect MovieClips.

Note that if the animation is interactive, i.e. the user can direct the animation while it's pausing, you need a couple of extra lines in the script.

2. If you actually want to make an entirely scriped animation (i.e. 'vertically'), you can use this script as a building block, but you need more.



Not everything that can be counted counts, and not everything that counts can be counted.



Return to posts index

Jessica Chapman
Re: Control timeline AS3
on Nov 1, 2010 at 9:36:29 am

Ah I see now. :)
Thank you so much for helping me out! I really appreciate it! :D

~Jess


Return to posts index

Mike Smith
Re: Control timeline AS3
on Nov 1, 2010 at 11:35:14 am

If all the frames have the same delay you could just change the frame rate ... http://www.flashadvisor.com/tutorial/Beginners/Frame_rate_in_flash-40.html


Return to posts index


Brodd Nesset
Re: Control timeline AS3
on Nov 1, 2010 at 2:23:55 pm

Generally, I'd argue against using the framerate as a timing measure or tool, if any preciscion is needed.
In the early days of actionscripting it was pretty common to use a frame counter to create a loop, i.e. 'go to the frame before this one X times before moving on'.
Everyone knows (or should know) that the framerate isn't static in the real world. An intricate animation will bring the FPS down, but this will be very different between computers. An animation that plays fine at say 25 FPS at your powerful computer, may likely play back at as little as 15 FPS on a more modest machine. Light content have been observed to play back even faster than the FPS set for the movie (i.e. in a 25 FPS movie, you can sometimes have playback at 27 FPS). Real FPS is unpredictable, and therefore not recommended. In the example, an intended two second pause made with a counter counting 50 frame loops, will instead last over three seconds on a computer striving to play back faster than 15 frames per second. Using a proper scripted timer, any pause will last the designated time, regardless. It's independent of the framerate (intended or obtained).
Sure, you can play a simple slidewhow like suggested with a super slow framerate. It takes away most if not all flexibility however. You can't have (or later introduce) fades between the elements, because the low FPS also means very jerky animation. Fades will be in crude steps, instead of a smooth transition.



Not everything that can be counted counts, and not everything that counts can be counted.



Return to posts index

Maizatul Akmar
Re: Control timeline AS3
on Aug 7, 2013 at 3:19:05 am

Thank you!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]