00:00
00:00
Newgrounds Background Image Theme

PalmVoe just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Tying Mc Frames To The Root

1,287 Views | 2 Replies
New Topic Respond to this Topic

As: Tying Mc Frames To The Root 2006-08-23 10:29:31


Click here for AS:Main!!!

This will just be a short one, and doesn't really require much of an introduction. It covers two ways to tie an MC's frames to those on the main timeline. It assumes a basic knowledge of timeline control and symbolic operators, and also MC handlers.

Now, in Flash, Movie Clips have within them their own timelines which are independant of the main one. Should you want them to stay tied to it, so if you pause the root or a clip's parent the MC will follow it, always being at the same place at, say, frame 15, you'll have to script it yourself.

This can be achieved by adding the following code to the clips you want tied:

onClipEvent(load){
var init:Number = _root._currentframe;
}
onClipEvent(enterFrame){
gotoAndStop((_root._currentframe - init) % _totalframes);
}

Elements:

var init - This variable is established when the clip loads. It is the frame the main timeline should be on when the is first loaded, and is required to determine the exact state of its loop the MC should be on. If you want the MC to start at a frame other than the first, you will have to add to this value.

Note - if the clip loads on any frame other than the first it is supposed to be in, e.g. if you reach a frame with the clip in by using gotoAndStop(); or prevFrame();, this value will not be correct. If you intend to use such functions, you can eliminate this bug by manually defining the first frame the clip should be on (var init:Number = #first frame.

_root._currentframe - init - The frame the _root is on, with the first frame the MC is on subtracted from that.

%_totalframes - This is important. Since MCs loop, if it is on the timeline for more frames than exist in the MC, you will have to reset the frame the clip goes to - it's no use telling it to go to frame 23 if the clip has only 20 frames.

The modulo (%) solves this by returning the remainder of the frame divided by the total frames, so in that example the result would be 3; a fine loop.

NB - This assumes you want to tie the clips to the _root. You can replace _root with the instance of any other clip, or _parent.

If you have lots of clips, you can probably avoid typing the same code out lots of times with a for - in loop, but that's something a little more complicated (i.e - it confuses me). Or you could name the clips with numbers and use a for loop, although that could cause problems with nested clips.

This method is perfectly adequate so long as you don't have a huge number of clips to add the script to. And unless you've got other script or want to use filters and blends (Flash 8), Graphics will work perfectly well for tying in to the main timeline too.

Okay, it wasn't that short.

_Paranoia_


BBS Signature

Response to As: Tying Mc Frames To The Root 2006-08-24 09:40:16


At 8/23/06 10:36 AM, West-End-Pro wrote: Cool tut. Didn't know this. =[

Its not that advanced, but a nice little effect. Good work paranoia. I'll use this soon, i'm guessing this means that whena user rightclicks and presses play, the MC's will stop too right?


BBS Signature

Response to As: Tying Mc Frames To The Root 2006-08-24 09:42:54


Cool idea.

Of course the other possibility is that when you pause _root, you recursively pause all movieclips in _root, making this script useless >:D

actually not really, since if there's only like 1 movieclip you want to pause, writing the whole recursive script would be a waste of time

Come join music competitions on Chips Compo and hang on our Discord!

Good artists copy. Great artists get banned from the Audio Portal.

BBS Signature