# Controlling loaded swf in website

**URL:** https://forum.kirupa.com/t/controlling-loaded-swf-in-website/305575
**Category:** flash
**Created:** [February 27, 2010, 5:55pm UTC](https://forum.kirupa.com/t/controlling-loaded-swf-in-website/305575 "2010-02-27T17:55:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![weedunc65](https://avatars.discourse-cdn.com/v4/letter/w/73ab20/32.png) [@weedunc65](https://forum.kirupa.com/u/weedunc65)
#### Post date: [February 27, 2010, 5:55pm UTC](https://forum.kirupa.com/t/controlling-loaded-swf-in-website/305575/1 "2010-02-27T17:55:55Z")

</div>

Hi

I’m creating a flash site, navigation is simple, or so I thought. Buttons along the top load external swf’s to the stage. As they are loaded and unloaded the swf’s animate in and out again on button clicks so the next one can come in.

I have suceeded in controlling the loaded swf’s to get them to animate onto the stage, but what I have added to animate them off again does not work. I don’t even get error messages, it is just ignored.

I have indicated below what I have added to try and ‘animate out’

Actionscript:

stop();  
//////// HOMEPAGE CONTENT LOADS ON PAGELOAD ///////////

addChild(loader);  
var swfloader:URLRequest=new URLRequest(‘contentboxhome.swf’);  
loader.load(swfloader);

/////////// BUTTONS //////////

////////////// HOME BTN ////////////////  
homebtn.addEventListener(MouseEvent.MOUSE\_OVER, mouseoverhome);  
homebtn.addEventListener(MouseEvent.MOUSE\_OUT, mouseouthome);  
homebtn.addEventListener(MouseEvent.MOUSE\_DOWN, mouseclickhome);

function mouseoverhome(event:MouseEvent):void {  
homebtn.gotoAndStop(2);  
}  
function mouseouthome(event:MouseEvent):void {  
homebtn.gotoAndStop(1);  
}

function mouseclickhome(event:MouseEvent):void{  
homebtn.gotoAndPlay(3);  
gotoAndStop(2); //background change

var loadedswf:Object=loader.content;  
\_\_\_from here is ignored  
loadedswf.gotoAndPlay(16);  
if (loadedswf.currentFrame == 30){  
loader.unload();  
} \_\_\_to here (tried an ‘if’ statement)  
}  
//////////////// ABOUT BTN /////////////////  
aboutbtn.addEventListener(MouseEvent.MOUSE\_OVER, mouseoverabout);  
aboutbtn.addEventListener(MouseEvent.MOUSE\_OUT, mouseoutabout);  
aboutbtn.addEventListener(MouseEvent.MOUSE\_DOWN, mouseclickabout);  
function mouseoverabout(event:MouseEvent):void {  
aboutbtn.gotoAndStop(2);  
}  
function mouseoutabout(event:MouseEvent):void {  
aboutbtn.gotoAndStop(1);  
}

function mouseclickabout(event:MouseEvent):void{  
aboutbtn.gotoAndPlay(3);  
homebtn.mouseEnabled=true;  
gotoAndStop(4);

var loadedswf:Object=loader.content;  
\_\_\_\_from here is ignored  
loadedswf.gotoAndPlay(16);  
loadedswf.addEventListener(Event.COMPLETE, animateout);  
function animateout(e:Event):void {  
loader.unload();  
} \_\_\_to here (this is the completelistener I mentioned)

addChild(loader);  
var swfloader:URLRequest=new URLRequest(‘contentboxabout.swf’);  
loader.load(swfloader); }

End of Actionscript

This is a sample of two of the 5 buttons, I have tried using both the ‘if’ function on all buttons and the ‘event complete’ function on all of them, and both are just ignored. No error messages, no unusual occurrences at all. The code is just skipped over and the swf I have requested to load, just animates in and replaces the one there currently. Only funny thing is that, despite the ‘loader.unload();’ being WITHIN the ‘complete’ function, it still seems to be fired. The swf’s never overlap each other.

Any help appreciated
