Solved

AS3: Removing child throws error

Posted on 2008-10-24
3
298 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
[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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where to download Adobe Flash Player 11.9.900.170 5 1,424
Array is not working ( AS2 ) 4 169
adobe flash plugin has crashed while listening to pandora 2 85
CD Rom not playing 13 86
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…
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 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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

739 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