?
Solved

AS3 addChild/RemoveChild issue

Posted on 2010-09-09
3
Medium Priority
?
1,074 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 33644792
0
 
LVL 3

Accepted Solution

by:
cconstable_work earned 1500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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