Container and swf condiftional statement

I neet to write a conditional statement that recognizes that a swf is loaded into a container. I’m not having a lot of success. Here’s my code:



function Button(event:MouseEvent):void {
    if (container_mc("1.swf") = true)    {
        imageLoader.load(imageRequest);
        container_mc.addChild(imageLoader);
    }
}


I’d appreciate it if anybody could steer me in the right direction.

add a COMPLETE event listener to the swf loader, e.g. ActionScript Code:
[LEFT]swfLoader.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]Event.[COLOR=#000080]COMPLETE[/COLOR], onSwfLoadComplete[COLOR=#000000])[/COLOR];
[/LEFT]

then under the onSwfLoadComplete function, set a boolean variable to true, e.g.

ActionScript Code:
[LEFT][COLOR=#000000]**var**[/COLOR] swfLoaded:[COLOR=#0000FF]Boolean[/COLOR];

[COLOR=#000000]function[/COLOR] onSwfLoadCompleteCOLOR=#000000[/COLOR]:[COLOR=#0000FF]void[/COLOR]
[COLOR=#000000]{[/COLOR]
swfLoaded = [COLOR=#000000]true[/COLOR];
[COLOR=#000000]}[/COLOR]
[/LEFT]

then on the mouse event function you have written above, do something like:
ActionScript Code:
[LEFT][COLOR=#000000]function[/COLOR] [COLOR=#0000FF]ButtonPressed[/COLOR]COLOR=#000000[/COLOR]:[COLOR=#0000FF]void[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR]
[COLOR=#000000]{[/COLOR]
imageLoader.[COLOR=#0000FF]load[/COLOR]COLOR=#000000[/COLOR];
container_mc.[COLOR=#000080]addChild[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]

i chnaged your function name from Button to ButtonPressed as tbh Button as a function name isnt very good practice, e.g. conflicting function name with the Button class etc

hope this helps =]

I’m having difficulty getting this to apply it to my fla and execute. Should it look like this, with the values entered in?


swfLoader.addEventListener(Event.COMPLETE, onSwfLoadComplete);

then this:


var swfLoaded:Boolean;

function onSwfLoadComplete(e:Event):void
{
    "1.swf" = true;
}

then this:


function Button(event:MouseEvent):void
{
    if ("1.swf")
    {
        imageLoader.load(imageRequest);
        container_mc.addChild(imageLoader);
     }
}

Okay, played with it some more, and I figured out how to tweak it to make it work. Thanks Magik5!

I thought I had it working. What I should have mentioned before was that I wanted this button to keep loading a series of swf files. So I wanted to continue the conditional statement to check and see if a swf was loaded. If not to ignore it, then go on to the next statement…etc. Here’s how I tried to extednd the code:


stop();

var imageRequest1:URLRequest = new URLRequest("1.swf");
var imageRequest2:URLRequest = new URLRequest("2.swf");
var imageRequest3:URLRequest = new URLRequest("3.swf");
var imageLoader:Loader = new Loader();
var swfLoaded:Boolean;


next_mc.addEventListener(MouseEvent.CLICK, ButtonPressed);
imageLoader.addEventListener(Event.COMPLETE, onSwfLoadComplete);

imageLoader.load(imageRequest1);
container_mc.addChild(imageLoader);

function onSwfLoadComplete(event:Event):void {
    swfLoaded = true;
}

function ButtonPressed(event:MouseEvent):void {
    if ("1.swf") {
        imageLoader.load(imageRequest2);
        container_mc.addChild(imageLoader);
    } else if ("2.swf") {
        imageLoader.load(imageRequest3);
        container_mc.addChild(imageLoader);
    }
}

next_mc.buttonMode = true;


I tried this but it keeps loading 2.swf even after 2.swf has loaded. Any thoughts, on how I might fix this?