load and unload movie in AS3
I'm one of those learning to transition from AS2 to AS3. I have two buttons on stage. I used the built in code snippet for unload and load Movie. Although the issue i'm having is that if i click button 1 and then I click button 2 the first movie still stays. If I use a unload(); then I have to click the button which loads this MC twice in order to get it to load again. Anyone know what I'm not comprehending? Here is the code provided by the snippet:
code:
b2.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_2);
import fl.display.ProLoader;
var fl_ProLoader_2:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad_2:Boolean = true;
function fl_ClickToLoadUnloadSWF_2(event:MouseEvent):void
{
if(fl_ToLoad_2)
{
fl_ProLoader_2 = new ProLoader();
fl_ProLoader_2.load(new URLRequest("effect.swf"));
fl_ProLoader_2.y = 100;
addChild(fl_ProLoader_2);
}
else
{
fl_ProLoader_2.unload();
removeChild(fl_ProLoader_2);
fl_ProLoader_2 = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_2 = !fl_ToLoad_2;
}
btn.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_5);
import fl.display.ProLoader;
var fl_ProLoader_5:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad_5:Boolean = true;
function fl_ClickToLoadUnloadSWF_5(event:MouseEvent):void
{
if(fl_ToLoad_5)
{
fl_ProLoader_5 = new ProLoader();
fl_ProLoader_5.load(new URLRequest("effect2.swf"));
fl_ProLoader_5.y = 150;
addChild(fl_ProLoader_5);
}
else
{
fl_ProLoader_5.unload();
removeChild(fl_ProLoader_5);
fl_ProLoader_5 = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_5 = !fl_ToLoad_5;
}
S