Hello everyone,
I’m kind of new to AS3
I created a flash file and i have several buttons on the main stage.
I have given the buttons instance names and whenever a button is clicked an external swf is loaded on the main stage.
The problem which occurred is that ehenever i click on the same button again i can see a glimpse of the previous swf that was loaded meaning that i didnt get rid of the swf on the click of another button.
What i want to achieve is to load the external swf and then when i click on another button i wish for it to unload.
Here is the code.
var externalSWF6:URLRequest = new URLRequest(“dress6.swf”);
var myLoader6:Loader = new Loader();
button6.addEventListener(MouseEvent.CLICK, onButtonClick6);
myLoader6.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfLoading6);
myLoader6.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete6);
function onButtonClick6(event:MouseEvent):void
{
myLoader6.load(externalSWF6);
}
function swfComplete6(event:Event):void
{
addChild(myLoader6);
myLoader6.x = 0
myLoader6.y = 0
}
function swfLoading6(event:ProgressEvent):void
{
}
var externalSWF7:URLRequest = new URLRequest(“dress7.swf”);
var myLoader7:Loader = new Loader();
button7.addEventListener(MouseEvent.CLICK, onButtonClick7);
myLoader7.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfLoading7);
myLoader7.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete7);
function onButtonClick7(event:MouseEvent):void
{
myLoader7.load(externalSWF7);
}
function swfComplete7(event:Event):void
{
addChild(myLoader7);
myLoader.x = 0
myLoader.y = 0
}
myLoader7.addEventListener(“UnloadMe”, unloadFunction7); // <-- My line
function unloadFunction7(event:Event):void {
// event.target is the loader reference… so cast it as Loader
Loader(event.currentTarget).unload();
}
function swfLoading7(event:ProgressEvent):void
{
}
var externalSWF:URLRequest = new URLRequest(“dress4.swf”);
var myLoader:Loader = new Loader();
button4.addEventListener(MouseEvent.CLICK, onButtonClick);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfLoading);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);
function onButtonClick(event:MouseEvent):void
{
myLoader.load(externalSWF);
}
function swfComplete(event:Event):void
{
addChild(myLoader);
myLoader.x = 0
myLoader.y = 0
}
function swfLoading(event:ProgressEvent):void
{
}
var externalSWF8:URLRequest = new URLRequest(“dress8.swf”);
var myLoader8:Loader = new Loader();
button8.addEventListener(MouseEvent.CLICK, onButtonClick8);
myLoader8.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfLoading8);
myLoader8.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete8);
function onButtonClick8(event:MouseEvent):void
{
myLoader8.load(externalSWF8);
}
function swfComplete8(event:Event):void
{
addChild(myLoader8);
myLoader.x = 0
myLoader.y = 0
}
myLoader8.addEventListener(“UnloadMe”, unloadFunction8); // <-- My line
function unloadFunction8(event:Event):void {
// event.target is the loader reference… so cast it as Loader
Loader(event.currentTarget).unload();
}
function swfLoading8(event:ProgressEvent):void
{
}
var externalSWF9:URLRequest = new URLRequest(“dress9.swf”);
var myLoader9:Loader = new Loader();
button9.addEventListener(MouseEvent.CLICK, onButtonClick9);
myLoader9.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfLoading9);
myLoader9.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete9);
function onButtonClick9(event:MouseEvent):void
{
myLoader9.load(externalSWF9);
}
function swfComplete9(event:Event):void
{
addChild(myLoader9);
myLoader.x = 0
myLoader.y = 0
}
function swfLoading9(event:ProgressEvent):void
{
}
//you can do something here while the swf is loading… }
button4.buttonMode = true;
button6.buttonMode = true;
button7.buttonMode = true;
button8.buttonMode = true;
button9.buttonMode = true;
button4.addEventListener(MouseEvent.ROLL_OVER,buttonOver4);
button4.addEventListener(MouseEvent.ROLL_OUT,buttonOut4);
function buttonOver4(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“over4”);
}
function buttonOut4(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“out4”);
}
button6.addEventListener(MouseEvent.ROLL_OVER,buttonOver6);
button6.addEventListener(MouseEvent.ROLL_OUT,buttonOut6);
function buttonOver6(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“over6”);
}
function buttonOut6(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“out6”);
}
button7.addEventListener(MouseEvent.ROLL_OVER,buttonOver7);
button7.addEventListener(MouseEvent.ROLL_OUT,buttonOut7);
function buttonOver7(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“over7”);
}
function buttonOut7(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“out7”);
}
button8.addEventListener(MouseEvent.ROLL_OVER,buttonOver8);
button8.addEventListener(MouseEvent.ROLL_OUT,buttonOut8);
function buttonOver8(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“over8”);
}
function buttonOut8(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“out8”);
}
button9.addEventListener(MouseEvent.ROLL_OVER,buttonOver9);
button9.addEventListener(MouseEvent.ROLL_OUT,buttonOut9);
function buttonOver9(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“over9”);
}
function buttonOut9(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“out9”);
}
If anyone can be of assistance i would greatly appreciate it:)