After loading 2 SWF files via two separate buttons, I am attempting to get one to recognize that the other is being viewed and unload. What would be the best way given the code here?
function matrixLoad(event:MouseEvent): void
{
if (fl_ToLoad3)
{
fl_Proloader3 = new fl_Proloader3();
fl_Proloader3.load(new URLRequest("assets/matrix1.swf"));
addChild(fl_Proloader3);
fl_Proloader3.x = 0;
fl_Proloader3.y = 300;
trace("Matrix1 Load");
}
else
{
fl_Proloader3.unload();
removeChild(fl_Proloader3);
fl_Proloader3 = null;
trace("Matrix1 UnLoad");
}
fl_ToLoad3 = !fl_ToLoad3;
}
function matrixLoad2(event:MouseEvent): void
{
if (fl_ToLoad4)
{
fl_Proloader4 = new fl_Proloader4();
fl_Proloader4.load(new URLRequest("assets/matrix2.swf"));
addChild(fl_Proloader4);
fl_Proloader4.x = 0;
fl_Proloader4.y = 300;
trace("Matrix2 Load");
}
else
{
fl_Proloader4.unload();
removeChild(fl_Proloader4);
fl_Proloader4 = null;
trace("Matrix2 UnLoad");
}
fl_ToLoad4 = !fl_ToLoad4;
}
matrix1.addEventListener(MouseEvent.CLICK, matrixLoad);
matrix2.addEventListener(MouseEvent.CLICK, matrixLoad2);
To get your code working, you should avoid some errors like using a variable and a Class with the same name :
here if you have a Class called
fl_Proloader3so your instance should have a different name (the same thing forfl_Proloader4 = new fl_Proloader4();).Also, I don't know how did you initialized
fl_ToLoad4andfl_ToLoad3, but normally they should have thefalsevalue at the beginning because your SWFs are not already been loaded, and in that case yourifstatements should be like this :but you can even do all that without using
Booleans by just using yourLoaderobjects, like this :which can give you something like this :
Edit :
An example :
Hope that can help.