Solved

How would you remove SWF's?

Posted on 2010-11-17
9
311 Views
Last Modified: 2012-05-10
So I have a problem occurring when I try the addChild/removeChild method. Maybe, I am doing something wrong, but my question is that when you click on a gallery page and its time to load the SWF... it loads fine, but when its time to remove the SWF that is where the problem is occurring. I don't get any errors when I output the movie, but when I click links, the following problem persists:

TypeError: Error #2007: Parameter child must be non-null.
      at flash.display::DisplayObjectContainer/removeChild()
      at nali_Project_3_Portfolio_fla::MainTimeline/frame10()
      at flash.display::MovieClip/gotoAndStop()
      at nali_Project_3_Portfolio_fla::intro_mc_1/frame108()

What seems to be the problem here? My code is as follows:
var requestMov:URLRequest = new URLRequest("gallery.swf");
var loaderMov:Loader = new Loader();
addChild(loaderObj);
loaderMov.load(requestMov);

Open in new window

and to remove it is removeChild(loaderObj).
0
Comment
Question by:beginnersdevelopment
  • 6
  • 3
9 Comments
 

Author Comment

by:beginnersdevelopment
ID: 34156405
Needs attention quick!
0
 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34156716
change addchild(loaderObj) to addchlid(loaderMov)
0
 

Author Comment

by:beginnersdevelopment
ID: 34156974
fixed, but not working still.

var requestMov:URLRequest = new URLRequest("gallery.swf");
var loaderMov:Loader = new Loader();
addChild(loaderMov);
loaderMov.load(requestMov);

Open in new window


and to remove: removeChild(loaderMov).

Still get an error. Whats the problem or is there another way of removing and adding swf's?
0
Industry Leaders: 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!

 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34157292
what error are you getting?
0
 

Author Comment

by:beginnersdevelopment
ID: 34159432
I am getting a lot of type errors when I test the movie out, but when I don't link my SWF's than I am good to go. My question turns around to be... What is the AS 3.0 code for adding and removing a swf file? I have researched this, but no solutions seem to work for me? Here is a preview of what I am doing: I am putting two galleries (gallery.swf and gallertwo.swf) in to a flash website. The code that I am using to put the SWF on my website is

var gallery:Loader = new Loader();
gallery.load(new URLRequest("nali_Project_3_gallery.swf"));
addChild(gallery);

Open in new window


and to remove it is

removeChild(gallery);

Open in new window


I use the same code with different function name for gallerytwo, but no luck and just errors like "TypeError: Error #2007: Parameter child must be non-null.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller."

gallerytwo doesn't get removed successfully either, but the other gallery does.

What am I doing wrong and what is the right script to do this? Am I adding the code to each button or what? I am bumping this up to 500 points, so someone please quickly help me.
0
 

Author Comment

by:beginnersdevelopment
ID: 34159521
I commented out the
removeChild

Open in new window

code and it seems to work without any errors, so the problem has to be that or that I am not putting the wrong code.  If I don't put this piece of code to remove SWF than my SWF's sit on top of the other pages. What am I doing wrong, somebody?
0
 
LVL 5

Accepted Solution

by:
GarrettChristopherson earned 500 total points
ID: 34159574
This is just a hunch:  I believe that your problem is scope, or when removeChild functions are called on the timeline. Along the lines of when removeChild is called on the timeline, try this:

var gallery:Loader = new Loader();
gallery.name = "gallery";
gallery.load(new URLRequest("nali_Project_3_gallery.swf"));
addChild(gallery);

and then just before you remove it from the stage, call

trace(gallery.name + " = gallery.name");  

do that for both of your loader objects, if you get an error with the trace(), try to find the place that the trace will report/print the name.  

as far as the #2025, this has to do with scope.

scope works likes this:

var mc:MovieClip = new MovieClip();
var gallery:Loader = new Loader();
gallery.load(new URLRequest("nali_Project_3_gallery.swf"));
mc.addChild(gallery); //this command makes gallery a child of mc

if you try: removeChild(gallery);  // it should throw a #2025 exception because you need to associate the relationship (parent & child).

where as mc.removeChild(gallery); //should remove gallery from the stage.

hope that helps
0
 

Author Comment

by:beginnersdevelopment
ID: 34160001
I got the solution, but noone on here helped as much as I would like. Thanks everyone for the help and I rewarded the points to the best solution I got.
0
 

Author Closing Comment

by:beginnersdevelopment
ID: 34160009
I found the answer at another EE. I love this  site.
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
powershell code to list items in dropdown 6 101
script to run a program on a windows share drive every 10 mins 2 36
Code Coverage and Coding Standards 2 43
size of file 1 22
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
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.

713 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