A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Loading in and external swf and unloading it from a MC button inside the external swf

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    22

    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

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    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"unloadHandlerfalse0true);
    function 
    unloadHandler(event:Event):void{
      
    ldr.unload();

    then dispatch that event from the loadee:
    PHP Code:
    unload_mc.addEventListenerMouseEvent.CLICKsendUnloadfalse0true);
    function 
    sendUnload(event:MouseEvent):void{
      var 
    e:Event = new Event("unloadRequest"true);
      
    dispatchEvent(e);


  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    22

    Talking 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!

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174

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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center