Solved

AS3 addChild/RemoveChild issue

Posted on 2010-09-09
3
1,046 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

809 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