PDA

View Full Version : removing external swf



adlib33
March 27th, 2009, 03:46 AM
Could someone help a newbie?

I'm trying to use various buttons for navigation on webpage. Having problems removing a swf that would have been added by a loader. The container mc can be removed but the swf added to it just stays. I read other topics on this subject but I don't understand where to put the removal events. If anyone has some typical code snippet.....


// everything down through the imageLoaded() function works as it is suppossed to

addChild(blogNewsMC);

blogNewsMC.x = 228;
blogNewsMC.y = 85;


var blogLoader:Loader;

function loadImage(url:String):void
{
blogLoader = new Loader();
blogLoader.load(new URLRequest(url));
blogLoader.contentLoaderInfo.addEventListener(Even t.COMPLETE, imageLoaded);
}

loadImage("blogNews.swf");

function imageLoaded(e:Event):void
{

blogNewsMC.addChild(blogLoader);
fadeInTween = new Tween(blogNewsMC, "alpha", None.easeNone, 0, 1, 2, true);
blogLoader.removeEventListener("COMPLETE", imageAlreadyLoaded);

}
// here is the first question. Is this the right way to write the Removers. As is written, does this do any real removing? I get errors with the unloadAndStop()

function imageAlreadyLoaded():void
{
blogLoader.unloadAndStop(true);
fadeInTween.stop();
}


}


one other thing, I can get the blogNewsMC and it's loaded swf to not be visible by setting their visible property to false upon other navigational button presses. Problem with this rather inelegant solution is the not-removed swf simply reloads over itself when made visible again. Maybe I should use a conditional that checks to see if the swf has loaded and if so, skip the loadImage function.


function loadImage(url:String):void
{
blogLoader = new Loader();
blogLoader.load(new URLRequest(url));
blogLoader.contentLoaderInfo.addEventListener(Even t.COMPLETE, imageLoaded);
}

if(blogNewsMC.content == !null) //<-----------------??????How do you write this correctly?
{imageAlreadyLoaded();
}else{
loadImage("blogNews.swf");}

if this is something that would work, how do you phrase the if condition to check to see if the swf has been loaded already so it won't continue to reload over itself?

Thanks in advance to anyone willing to help....

CS4/FP9

Elementss
March 27th, 2009, 05:10 AM
i think you shuld add

blogLoader.unload;

before you load in your loader...

. unload << unloads data from loader and that way it wont load on itself...






function loadImage(url:String):void
{

blogLoader.unload;
blogLoader = null;
blogLoader = new Loader();
blogLoader.load(new URLRequest(url));
blogLoader.contentLoaderInfo.addEventListener(Even t.COMPLETE, imageLoaded);
}


i think that should work... images and swf wont load on each other in the loader..

why are you loading to the loader each time ?

adlib33
March 27th, 2009, 02:18 PM
Thanks for the reply but I dont seem able to make this work. Using blogLoader.unload/null as you suggested doesn't let everything reload. Moving these commands around just gives me errors.

I'm trying to get the stage clear and the appropriate info loaded and tween'd each time a user presses a navigational button. As the other sections work fine, could it be, in this case, that the blog.swf that the loader loads is a third-party newsReader that doesn't "let go" and is impossible to clean up (as per Skinners AS3 article)????

As far as loading to the loader each time......could I be doing something else?

Maybe thats my real question: How do I write the if (conditional) statement to make flash check if the swf has already been loaded, if not, load, if so, skip loading