|
-
Loading in and external swf and unloading it from a MC button inside the external swf
Hi,
I used to do this fine with AS2 and now i'm struggling to get it to work in AS3.
my code is as follows:
PW1.addEventListener( MouseEvent.CLICK,loader1 );
//==================== PS function =============================================
var ldr:Loader = new Loader();
function loader1 (evt:MouseEvent) {
ldr.load(new URLRequest("projectSheet.swf"));
ldr.contentLoaderInfo.addEventListener (Event.COMPLETE, loaded);
}
var thisMovieClip:MovieClip;
function loaded (evt:Event) :void {
stage.addChild(ldr);
thisMovieClip = MovieClip(ldr.content);
}
function unloader (evt:MouseEvent) :void {
stage.removeChild(ldr);
}
on the main stage frame 1
then on the external swf frame 1:
//unload_mc.buttonMode = true;
//unload_mc.addEventListener( MouseEvent.CLICK, unloader );
unload_mc is a movieClip that I want to use to unload it's self. The function unloader is in frame 1 of the main stage.
I also have code making movieClips come to the front when rolled over:
this.addEventListener(MouseEvent.MOUSE_OVER, onBringToTop, false, 0, true);
function onBringToTop(evt:MouseEvent):void {
setChildIndex(MovieClip(evt.target), numChildren-1);
}
also on the main timeline.
please help
-
in your main swiff, add a custom listener to the Loader... I'll use a simple string, but best practice would probably be to use a custom event:
PHP Code:
ldr.addEventListener("unloadRequest", unloadHandler, false, 0, true); function unloadHandler(event:Event):void{ ldr.unload(); }
then dispatch that event from the loadee:
PHP Code:
unload_mc.addEventListener( MouseEvent.CLICK, sendUnload, false, 0, true); function sendUnload(event:MouseEvent):void{ var e:Event = new Event("unloadRequest", true); dispatchEvent(e); }
-
Thankyou
Thanks thats great I looked everywhere and couldn't find the answer they've really changed the way you load with 3.0 I'm doing some tutorials to play catch up and get my head around it .
Ta very much!
-
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|