Solved

AS3 addChild/RemoveChild issue

Posted on 2010-09-09
3
1,039 Views
Last Modified: 2013-11-11
I have a menu on the main timeline that places movieclips on the stage, but as I add additional movieclips via the menu the movieclips are stacking behind the first placed movieclip.

I've tried using removeChildAt(0); but it either throws an error or removes the menu.

what is the best way to remove the movieclip prior to the next one being added at the index below the menu?

var newPlane:plane1_mc;
var newAEP:AEP_NAS_mc;

this.container_mc.TDLSF_mc.addEventListener(MouseEvent.MOUSE_OVER, TDLSFClick);
function TDLSFClick(e:MouseEvent):void {
	container_mc.TDLSF_mc.y = 198;
	//var myTween:Tween = new Tween(container_mc.TDLSF_mc, "y", Regular.easeOut, 241, 190, .5, true);
}

this.container_mc.TDLSF_mc.addEventListener(MouseEvent.MOUSE_OUT, TDLSFOut);
function TDLSFOut(e:MouseEvent):void {
	container_mc.TDLSF_mc.y = 253;
	//var myTween:Tween = new Tween(container_mc.TDLSF_mc, "y", Strong.easeOut, 190, 241, 1, true);
}

this.container_mc.IPSF_mc.addEventListener(MouseEvent.MOUSE_OVER, IPSFClick);
function IPSFClick(e:MouseEvent):void {
	container_mc.IPSF_mc.y = 172;
}

this.container_mc.IPSF_mc.addEventListener(MouseEvent.MOUSE_OUT, IPSFOut);
function IPSFOut(e:MouseEvent):void {
	container_mc.IPSF_mc.y = 253;
}

this.container_mc.TDLSF_mc.Link16_btn.addEventListener(MouseEvent.CLICK, Link16);
function Link16(e:MouseEvent):void {
	newPlane = new plane1_mc(); 
	newPlane.x = 0; 
	newPlane.y = 0;
	newPlane.name = "newPlane";
	this.addChildAt(newPlane,0); 
}
this.container_mc.PMDS_mc.addEventListener(MouseEvent.CLICK, PMDS);
function PMDS(e:MouseEvent):void {
	newAEP = new AEP_NAS_mc(); 
	newAEP.x = 0; 
	newAEP.y = 0;
	newAEP.name = "newAEP";
	this.addChildAt(newAEP,0); 
}

Open in new window

0
Comment
Question by:pixystk
3 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 33644792
0
 
LVL 3

Accepted Solution

by:
cconstable_work earned 500 total points
ID: 33659810
When using event listeners I'm not sure that "this" works the way you intend it to which is why you are removing the menu when using 0.

Best thing to do is have a container movie clip (myContainer_mc) for the movie clips you will be putting on stage. It would be best to load a movieclip to this container when the program first loads that way you can do this:

myContainer_mc.removeChildAt(0);
myContainer_mc.addChildAt(newMCfromMenu, 0);

I can't really tell what is what from your code but here is some other ways of targeting movie clips that I use.

Menu_mc.addEventListener(MouseEvent.MOUSE_UP, reportClick);
function reportClick(e:MouseEvent):void {
trace(e.target);
trace(e.target.name);
trace(e.target.parent);
trace(e.target.parent.name);
      e.target.parent.addChildAt(myNewMC, 0);
      e.target.parent.removeChild(e.target);
}
0
 

Author Closing Comment

by:pixystk
ID: 33730425
not exactly what i needed but definately put me in the right direction, thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now