Create a wrapper class that extends MovieClip in your main app that will handle
the loading of the external swf's (into a sub
movieclip of the wrapper)
// pseudo code
import mx.utils.Delegate;
class SWFLoader extends MovieClip {
//
private var holder_mc:MovieClip;
private var loader_mcl:MovieClipLoader;
//
function SWFLoader() {
trace("SWFLoader ::: CONSTRUCTOR");
this.loader_mcl = new MovieClipLoader();
this.loader_mcl.addListener(this);
this.createEmptyMovieClip("holder_mc", this.getNextHighestDepth());
this.loader_mcl.loadClip("external.swf", this.holder_mc);
}
//
private function onLoadInit(_mc:MovieClip):Void {
trace("SWFLoader ::: onLoadInit");
// listen for "frameReached" event, dispatched by external swf
_mc.addEventListener("frameReached", Delegate.create(this,
this.frameReachedHandler));
}
//
private function frameReachedHandler(o:Object):Void {
trace("SWFLoader ::: frameReachedHandler");
trace(" - frame reached: "+o.frame);
// do something here depending on which frame has been reached
// or dispatch an event to listeners
}
}
// end pseudo code
Then in the external swf, decorate it with EventDispatcher.
// frame 1 - main timeline of external swf
import mx.events.EventDispatcher;
EventDispatcher.initialize(this);
// some other frame in external swf
// dispatch event to listener
this.dispatchEvent({type:"frameReached", frame:this.__currentframe});
It's quick and dirty, but gets the job done ;-)
Part from adding the EventDispatcher stuff in the animation swf's you don't
have to change them.
And in your main app you still get to work in a clean way, using a Class and
event dispatching.
regards,
Muzak
----- Original Message -----
From: "Glen Pike" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Monday, October 16, 2006 12:15 AM
Subject: [Flashcoders] Casting external SWF's
> Hi,
>
> I am working on a project where I have been supplied a number of animation
> scenes in separate SWF's due to the size of the
> finished animations. All the animation in the SWF's is on the root timeline
> and some of it is in separate scenes :(
>
> In order to sequence the animations, I am preloading these SWF's into a
> shell application then playing them in order
> I need to be able to detect when certain frames are reached inside these
> animations in order to fire off various events - like
> playing the next one, etc.
>
> Rather than extend the functionality of MovieClip by adding to the
> prototype - the AS1 way - is there a better way of gaining
> some control over these clips?
>
> I would love to cast them as a subclass of movieclip which dispatches
> events and can play backwards forwards, etc. but as I am
> dealing with the root timeline, I guess I cannot cast the MovieClip object as
> something with extra functionality?
>
> I have the FLA's so at worst, I could move all the frames from the root
> timeline into a clip linked to my subclass, but as
> there are a lot of scenes, this is not a desired course of action.
>
> Thanks for your help
>
> Glen
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com