Solved

AS3 addChild/RemoveChild issue

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
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.

732 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