Solved

AS3: Removing child throws error

Posted on 2008-10-24
3
295 Views
Last Modified: 2013-11-11
Here's what I'm trying to do:
1. Load swf
2. Add children movieclips to swf
3. click one of the children movieclips
4. unload swf and start all over again

However I keep getting the error "The supplied DisplayObject must be a child of the caller". Even when I simplify the code down to this:

function loadSwf(newSwf) {
            swfLoader.load(new URLRequest(newSwf));
              swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoad);
            
            function onSwfLoad(e:Event) {
                  curSwf = e.target.content;
                  stage.addChild(curSwf););
                  unloadSwf();
            }
}

function unloadSwf() {
      this.removeChild(curSwf);
}


I continue to get the error. What am I doing wrong? Argh!
0
Comment
Question by:katyjack
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 22799202
The following works:

<code>

-V
var swfLoader:Loader = new Loader();

var curSwf:MovieClip = new MovieClip();
 

loadSwf("someMovie.swf");
 

function loadSwf(newSwf) {

	swfLoader.load(new URLRequest(newSwf));

	swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoad);

}
 

function unloadSwf() {

	stage.removeChild(curSwf);

}
 

function onSwfLoad(e:Event) {

	curSwf = e.target.content;

	trace(curSwf);

	stage.addChild(curSwf);

	unloadSwf();

}

Open in new window

0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 23199659
Did this work for you?

-V
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
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.

910 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

24 Experts available now in Live!

Get 1:1 Help Now