Skip to main content
Inspiring
August 28, 2009
Answered

Checking if a swf is already loaded

  • August 28, 2009
  • 1 reply
  • 1318 views

I want to know how to check whether a SWF is loaded or not.

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

It finally worked! Thanks for the code, that gave me a hint and I got it right this time

But for some reason when I roll out quickly I am getting this error:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

at flash.display::DisplayObjectContainer/removeChild()

Here's my code now:

import gs.*;

import gs.easing.*;

rect.addEventListener(MouseEvent.MOUSE_OVER, scaleUp);

rect.addEventListener(MouseEvent.MOUSE_OUT, scaleDown);

function scaleUp(e:MouseEvent):void

{

     TweenMax.to(rect, 0.4, {scaleX:4, scaleY:4, onComplete:addPreloader});

}

function scaleDown(e:MouseEvent):void

{

     TweenMax.to(rect, 0.2, {width: 240.9, height: 94, onStartListener:removeF});

}

var req:URLRequest = new URLRequest("Circular Preloader.swf");

var loader:Loader = new Loader();

var loaded:Boolean = false;

function addPreloader(e:Event = null):void

{

     if(loaded == false) {

     loader.load(req);

     loader.contentLoaderInfo.addEventListener(Event.COMPLETE, addF);

     loaded = true;

     trace("loading swf...")

     } else {

          addChild(loader);

          trace("we only added the swf to stage this time")

     }

}

function addF(e:Event):void

{

     addChild(loader);

     loader.x =  rect.x - loader.width;

    loader.y =  rect.y - loader.height;

}

function removeF(e:Event):void

{

     removeChild(loader);

     trace("swf was removed");

}

     


Try:

function removeF(e:Event):void

{

     if(this.contains(loader)) removeChild(loader);

     trace("swf was removed");

}

1 reply

Inspiring
August 29, 2009

Event.COMPLETE

Inspiring
August 29, 2009

no that's not what I'm looking for... I have a mouse over and mouse out event listeners. On the mouse over, I want that rectangle (from my previous post) to scale up and then load a swf to its center, and then when I roll out, I want the rect to go back to its initial size and removeChild which is in this case the loaded swf. I do not want to unload the swf, I just want to remove if from the stage, so that when I roll over the rect again, I could simply say addChild to add it back to stage and display it on the rect's center rather than loading it all over again. So basically I will have to use a conditional statement, something like:

if (loaded == true) {

addChild(loader);

} else {

loader.load();

addChild(loader);

}

but I just cannot figure out a way to achieve this boolean so I could use it this way...

Inspiring
August 29, 2009

Your original post was about checking is SWF loading was complete, was not it? So, why is it a no?

What was not added to stage cannot be removed from it. So, in your case you, perhaps, need to to remove a listener from loader that adds it to stage if mouse was rolled out of rectangle. The loader is still safe and you can reuse it in the future.