Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How would you remove SWF's?

Posted on 2010-11-17
9
Medium Priority
?
318 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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