Event for movie clip loading
Is there an event for when a movieClip
loads that I can have other aspects of my flash movie react to? I would like to add an event listener
for when movieClipOne loads that can trigger a di开发者_C百科fferent function in my actionscript (dim the rest of the stage).
movieClipOne.addEventListener(Event.NAME, dimFunction);
Also, if anyone can tell me the Event.NAME
for when the application initially loads that would be helpful too.
Not sure what you mean by "loading". if you're using a Loader object you'll need to attach events to contentLoaderInfo
which is a LoaderInfo
object.
If you're just trying to attach an event to a movie clip when it's added to the stage, you can use the addedToStage
event which is inherited from DisplayObject
. For a complete list of supported events, just check out the docs about MovieClip
If you are using the Loader class to load your MovieClip, then you can add event listeners to its contentLoaderInfo property:
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete);
and you can also add an INIT listener too:
loader.contentLoaderInfo.addEventListener(Event.INIT, handleInit);
each of those functions should take an Event as their sole parameter, for example:
function handleComplete(e:Event):void
{
//do something
}
Edit: Given what you have posted as your final solution, I would say that since you are using code on the timeline, you could add event listeners to the swfs loaderInfo object, so on frame 1:
this.loaderInfo.addEventListener(Event.COMPLETE, handleComplete);
{
// do something here
}
I don't think checking for the existence of some other element of the swf is the best practice although it obviously works in your case and with careful choosing / trial and error it would work for others too.
this.addEventListener(Event.ENTER_FRAME,checkLoaded)
function checkLoaded(e:Event){
if(mtERGOlink){
// code reacting to mtERGOlink
this.removeEventListener(Event.ENTER_FRAME,checkLoaded)
}
}
This allowed me to compile and run the project as I desired. I believe that it does not make the mtERGOlink code accessable until the mtERGOlink object is available on the stage.
Thank you for the other answers - they helped lead me to this solution.
精彩评论