Ok guys, please help me! Here´s the thing, On frame 446 in the main timeline I have a button (btn_habitat) that when clicked it launches an external swf and moves the timeline to frame 461. Everything works fine. The swf loads and it shows on stage.

Now, on frame 461 there´s another button called btn_home2 and what I want is that when this button is clicked I want it to unload/remove the swf playing on stage.

I don´t know how to reference to the code inside the btn_habitat button. NOTE that the btn_home2 has no code within it as btn_habitat does.

I attach the code that is within the button (btn_habitat) and that loads the swf:

var thisLoader:Loader = new Loader(); 
thisLoader.contentLoaderInfo.addEventListener(Event.INIT, doneLoading);

var thisMC:MovieClip = new MovieClip();
stage.addChild(thisMC);			// Add empty MC initially so the nextClip function can be generic

// Removes old MC and gets the next one, waiting until when it has initialized beore adding it to the stage
function nextClip():void {
	thisLoader.load(new URLRequest("habitat.swf"));
}

// Tell AS that the loaded file is a movie clip and add it to the stage.
function doneLoading(neve:Event):void {
	stage.removeChild(thisMC);
	thisMC = MovieClip(thisLoader.content);
	thisLoader.unload();
	stage.addChild(thisMC);
	thisMC.play();
	thisMC.x=5;
	thisMC.y=-25;
}

// "Next button" just calls a function that goes to the next file name (mod the number of files in the list)

//btn_habitat.addEventListener(MouseEvent.CLICK, playNext);

function playNext(ev2:MouseEvent) {
MovieClip(parent).gotoAndPlay(447);
trace("hola");
nextClip();
this.removeEventListener(MouseEvent.CLICK, playNext);
}

Now I attach the code in frame 461:

stop();

btn_home2.addEventListener(MouseEvent.CLICK, mouseDownHandler7);

function mouseDownHandler7(ev:MouseEvent):void {
    gotoAndPlay(461);
   //WHAT DO I PUT HERE TO UNLOAD/REMOVE THE SWF?!?!?
   this.removeEventListener(MouseEvent.CLICK, mouseDownHandler7);
}

Thanx in advance!

Member Avatar for rajarajan2017

Please provide the source

Member Avatar for rajarajan2017

Loading swf:

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("introt.swf"));
addChild(my_loader);
my_loader.name = "case";
my_loader.x = 62.1;
my_loader.y = 125.5;

unLoading swf:

btcasa.addEventListener(MouseEvent.CLICK, clicked);
function clicked(event:MouseEvent):void{
	var child:DisplayObject = getChildByName("case");
if (child) removeChild(child);
}

Hope this helps!

Thanx a lot rajarajan07, I´ve been trying with the code u gave me, however it's kinda working but not very good.

In my original code the external swf loads into a MC. (I will upload the file so u can see what I'm talking about.)

Just remember that On frame 446 in the main timeline I have a button (btn_habitat) that when clicked it launches an external swf (change the path to a swf of yours) and moves the timeline to frame 461. Everything works fine. The swf loads and it shows on stage.

Now, on frame 461 there´s another button called btn_home2 and what I want is that when this button is clicked I want it to unload/remove the swf playing on stage.

I don´t know how to reference to the code inside the btn_habitat button. NOTE that the btn_home2 has no code within it as btn_habitat does.

On the other hand, I played a little bit with the code u gave me, and it's working but not as good as I want....it loads the swf in a very small size (it reduces the size of everything) and when I click the buttons of the external swf it messes with the buttons of the original swf.

Please rajarajan07 keep helping me!!

Thanx a lot by the way!

Regards;
chevechiva

Member Avatar for rajarajan2017

A Little Changes in the btn_habitat:

var thisLoader:Loader = new Loader(); 
thisLoader.contentLoaderInfo.addEventListener(Event.INIT, doneLoading);

var thisMC:MovieClip = new MovieClip();
thisMC.name = "case";

function doneLoading(neve:Event):void {
	thisMC.addChild(thisLoader);
	stage.addChild(thisMC);
	thisMC.x=200;
	thisMC.y=-25;
}

function playNext(ev2:MouseEvent) {
MovieClip(parent).gotoAndPlay(447);
thisLoader.load(new URLRequest("nav.swf"));
this.removeEventListener(MouseEvent.CLICK, playNext);
}

Now come to 461:

stop();

btn_home2.addEventListener(MouseEvent.CLICK, mouseDownHandler7);

function mouseDownHandler7(ev:MouseEvent):void {
    	gotoAndPlay(461);

	if (btn_habitat) trace("true");
	else trace("false");

/*
First check the btn_habitat is present at the time or not, It return false
because that button is not present. You must extend that button frame to the current frame (461) then only you can access that button to process your request*/

if (btn_home2) trace("true");
	else trace("false");

//It returns true, because you have the access while you have that button in the current frame

//After extend the frame of btn_habitat then try the following code

if (btn_habitat){
		var child:DisplayObject = btn_habitat.getChildByName("case");
		if (child) removeChild(child);}

}

Member Avatar for rajarajan2017

Hey I got it!
Now Come to 461

btn_home2.addEventListener(MouseEvent.CLICK, mouseDownHandler7);

function mouseDownHandler7(ev:MouseEvent):void {
    gotoAndPlay(461);
	stage.removeChildAt(1);
}

It works!

hi again rajarajan07, first of all, thanx for helping me out with this and for giving me some of your precious time.

Guess what? I changed the code and it was not working.....then I changed the external swf and it works! but somehow it doesn´t work with the original external swf that I intend to use. It throws the following error:

[SWF] C:\Users\JUANJO\Documents\ARQME\WEBSITE\habitat.swf - 211973 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at org.FlepStudio::Main/moveItems()[C:\Users\JUANJO\Documents\ARQME\WEBSITE\org\FlepStudio\Main.as:390]
Debug session terminated.

I don´t know why....just don´t know damn it! I will attach the files of the external swf so maybe you can help me out with detecting the error.

Also I found another solution but instead of usin stage.addchild, I used addchild but it loads the swf ver awfuly and the buttons of the external swf messes with the buttons of the actual stage.

Thanx again and have a nice day! Save me!

Best regards!

Hey rajarajan07, guess what? I fixed it! Here´s the tip:

In the main.as file from the external swf (which is in the org folder) I changed:

removeEventListener(Event.ADDED_TO_STAGE,init);

to

this.removeEventListener(Event.ADDED_TO_STAGE,init);

Then it threw the same error but referring to the moveItems function, since I´m not using that function anymore I just commented it out.

And voilá!! it worked.... thanx very very much for your help

Have a great day!

Best regards!

Member Avatar for rajarajan2017

Oh! Great! Have a nice day for you too....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.