0
votes

I just implemented that last piece of code you sent over - many thanks!! This is the FULL context of this frame, the complete code with the other buttons as well, in case that is causing the problem. The 19 errors I get with this piece of code is:

1120: Access of undefined property fl_ProLoader_01

 stop();

 //home button

 mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_01_1,false,0,true);

 function fl_ClickToLoadUnloadSWF_01_1(event:MouseEvent):void
 {
     removeChild(fl_ProLoader_01);
     fl_ProLoader_01.unloadAndStop();
     fl_ProLoader_01 = null;
 }

 mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_01_1,false,0,true);

 function fl_ClickToGoToAndStopAtFrame_01_1(event:MouseEvent):void
 {
    removeChild(fl_ProLoader_01);

 }

 mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds_01_1,false,0,true);

 function fl_ClickToStopAllSounds_01_1(event:MouseEvent):void
 {
    SoundMixer.stopAll();
 }

 mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_01_2,false,0,true);

 function fl_ClickToGoToAndStopAtFrame_01_2(event:MouseEvent):void
 {
    gotoAndStop(1);
 }

 //other buttons at the bottom

 mythbutt_aboriginal_culture.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_01_1);

 function fl_ClickToGoToWebPage_01_1(event:MouseEvent):void
 {
    navigateToURL(new URLRequest("http://www.bigmyth.com/fullversion/password033/download/ABORIGINAL_CULTURE.pdf"), "_blank");
 }

 mythbutt_aboriginal_pantheon.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_01_2);

 function fl_ClickToGoToWebPage_01_2(event:MouseEvent):void
 {
    navigateToURL(new URLRequest("http://www.bigmyth.com/fullversion/password033/download/ABORIGINAL_PANTHEON.pdf"), "_blank");
 }

 mythbutt_aboriginal_exercises.addEventListener( MouseEvent.CLICK, fl_ClickToGoToWebPage_01_3);

 function fl_ClickToGoToWebPage_01_3(event:MouseEvent):void
 {
    navigateToURL(new URLRequest( "http://www.bigmyth.com/fullversion/password033/download/ABORIGINAL_EXERCISES.pdf"), "_blank");
 }

 //start button

 //Change your event handler function.
 start_button_aboriginal.addEventListener(MouseEvent.CLICK,fl_ClickToLoadSWF_01_2);

 function fl_ClickToLoadSWF_01_2(event:MouseEvent):void {
     fl_ProLoader_01=new ProLoader  ;
     fl_ProLoader_01.load(new URLRequest("myths/myth_aboriginal.swf"));
     fl_ProLoader_01.contentLoaderInfo.addEventListener(Event.COMPLETE, 

         //Using closure callback instead of *onComplete_1* function
         function( e : Event ) { 
                e.currentTarget.content.addEventListener( Event.ENTER_FRAME, OEF_01);
         });
     addChild(fl_ProLoader_01);
     fl_ProLoader_01.x=323;
     fl_ProLoader_01.y=41;

 //Swap the event handlers,no need for flag,clear code blocks
     start_button_aboriginal.removeEventListener(MouseEvent.CLICK,fl_ClickToLoadSWF_01_2);
     start_button_aboriginal.addEventListener(MouseEvent.CLICK,fl_ClickToUnLoadSWF_01_2);
 }

 function fl_ClickToUnLoadSWF_01_2(event:MouseEvent):void {
     fl_ProLoader_01.removeEventListener(Event.ENTER_FRAME,OEF_01);

     removeChild(fl_ProLoader_01);
     fl_ProLoader_01.unloadAndStop();
     fl_ProLoader_01=null;

     start_button_aboriginal.removeEventListener(MouseEvent.CLICK,fl_ClickToUnLoadSWF_01_2);
 }

 function OEF_01(e:Event):void {
      if (e.currentTarget.currentFrame==e.currentTarget.totalFrames) {
           e.currentTarget.stop();
           fl_ClickToUnLoadSWF_01_2(null);
      }
 }
1
From the sample code you have provided you have two places where you do removeChild(fl_ProLoader_1), but you check if fl_ProLoader_1 is null in only the first place. And then you null it. So if that happens first, and later in code you try to removeChild this object again, then it is still null and thus your error would come up.Garry Wong

1 Answers

2
votes

I think @GarryWong is right. If you click the start button after the external swf has been loaded and before his timeline has finished you will get an error.

I've changed your implementation, please try this. No need to check for null object.

UPDATE


//Change your event handler function.
startbutton.addEventListener(MouseEvent.CLICK,fl_ClickToLoadSWF_1_2);

function fl_ClickToLoadSWF_1_2(event:MouseEvent):void {
    fl_ProLoader_1=new ProLoader();
    fl_ProLoader_1.load(new URLRequest("myths/myth_aboriginal.swf"));
    fl_ProLoader_1.contentLoaderInfo.addEventListener(Event.COMPLETE, 
                                                      //Using closure callback instead of *onComplete_1* function
                                                      function( e : Event ) {
                                                          e.currentTarget.content.addEventListener(Event.ENTER_FRAME, OEF_1);
                                                          });
    addChild(fl_ProLoader_1);
    fl_ProLoader_1.x=207;
    fl_ProLoader_1.y=41;

    //Swap the event handlers,no need for flag,clear code blocks
    startbutton.removeEventListener(MouseEvent.CLICK,fl_ClickToLoadSWF_1_2);
    startbutton.addEventListener(MouseEvent.CLICK,fl_ClickToUnLoadSWF_1_2);
}

function fl_ClickToUnLoadSWF_1_2(event:MouseEvent):void {
    fl_ProLoader_1.removeEventListener(Event.ENTER_FRAME,OEF_1);

    removeChild(fl_ProLoader_1);
    fl_ProLoader_1.unloadAndStop();
    fl_ProLoader_1=null;

    startbutton.removeEventListener(MouseEvent.CLICK,fl_ClickToUnLoadSWF_1_2);
    //Use the below line only if you want to repeat the procedure of loading the *Proloader*, otherwise omit it.
    startbutton.addEventListener(MouseEvent.CLICK,fl_ClickToLoadSWF_1_2);
}

function OEF_1(e:Event):void {
    if (e.currentTarget.currentFrame==e.currentTarget.totalFrames) {
        e.currentTarget.stop();
        fl_ClickToUnLoadSWF_1_2(null);
    }
}

Sorry but I haven't Flash installed in my PC right now so maybe there will be some mistakes in my code. You made me boot my Windows partition!