Solved

AS3: Removing child throws error

Posted on 2008-10-24
3
294 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
Comment Utility
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
Comment Utility
Did this work for you?

-V
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
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 what frame rate is, how to control it and what effect it has on the video.

744 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

12 Experts available now in Live!

Get 1:1 Help Now