?
Solved

AS3 addChild/RemoveChild issue

Posted on 2010-09-09
3
Medium Priority
?
1,104 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.

650 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