Solved

AS3: Removing child throws error

Posted on 2008-10-24
3
296 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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.
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.

831 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