Solved

How would you remove SWF's?

Posted on 2010-11-17
9
308 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
 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34157292
what error are you getting?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Autoit restart command not working 6 58
inactive users 13 71
exchange, scripts 3 61
Stupid git question 2 63
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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 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.

895 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