View Full Version : timeline control of externally loaded swfs

11-02-2009, 04:49 PM
So - still new to AS 3.0 -

I have a set of SWFs loaded, and have successfully added them to the stage, and can assign basic methods ( gotoAndPlay(), stop() etc..) based on MouseEvents. I can't quite figure out, however, how to assign methods based on frame number or label, triggered by labels on the currently playing SWF timeline.

So, for example: externally loaded swf starts playing, and a listener is set up to listen for a "stop" label, which would activate stop();

I can obviously just drop a stop(); in the timeline of the loaded swf, but I am really trying to banish all code from timelines, period.

I could set up a frame-based listener to decide if a label exists at the current frame, and then to evaluate if that frame label == "stop"... but that seems pretty messy, and because it has to run at every frame, CPU heavy...

So - the question is really about listeners, I guess. What event would I listen for? Something like a MouseEvent - but ... a LabelEvent instead ;) Obviously - this doesn't exist, but something like it would be perfect.

Any ideas?

Or am I just overcomplicating things, and, a couple simple actions scattered here and there isn't that big of a deal...

cheers -


11-02-2009, 07:42 PM
I would just include a dispatchEvent in the swfs right at the frame I want and simply make my main file listen for these events and take action.

11-02-2009, 08:03 PM
Not sure if I follow you ;)

are you saying that the eventDispatch routine would be included in the external swf? I'm actually hoping to include zero code in any timeline. The idea would be to create a listener in the main.as class to listen for frame label changes.

I actually got this working:

targetInstance.addEventListener(Event.ENTER_FRAME, checkLabel, false, 0, true);


private function checkLabel(evt:Event){
trace(targetInstance.name + " current frame = "+ targetInstance.currentLabel);
if (targetInstance.currentLabel=="stop"){
targetInstance.removeEventListener(Event.ENTER_FRA ME,checkLabel);

which does work, but I'm a little hesitant to incorporate it as I would guess its a bit cycle heavy.

Is it possible to create a custom listener to make this work?

thx for the reply ;)

11-02-2009, 08:36 PM
I'm actually hoping to include zero code in any timeline. That's too bad since dispatching an event directly from the swf timeline would save you a lot of resources and troubles. Other than that you only have enterframe to check the frame labels but do it globally at least and not with an enterframe event for each swf.