-
Load and remove an external SWF.. i've a problem to remove it
I load an external swf in this way
PHP Code:
var termini_Loader:Loader = new Loader(); addChild(termini_Loader);
var termini_url:URLRequest=new URLRequest("termsnconditions.swf"); termini_Loader.load(termini_url); addChild(termini_Loader) termini_Loader.name="terms"
This external swf haves a close button that i want to use to kill itself. I want to put the code inside the external swf itself, not in the principal swf that loads it.. then i've wrote
PHP Code:
termini.closebtn.addEventListener(MouseEvent.CLICK, function() { (root as MovieClip).parent.removeChild(getChildByName("terms")) })
but when i test it from the principal swf, this is the error
TypeError: Error #1009: Cannot access a property or method of a null object reference
What i've wrong?
-
Senior Member
You cannot use removeChild on the loaded swf, because it was not created that way. You can either remove the Loader object or unload the Loader object using that close button.
- The right of the People to create Flash movies shall not be infringed. -
-
because it was not created that way
i don't understand.
If i apply the removeChild in the principal swf, so:
var termini_Loader:Loader = new Loader();
addChild(termini_Loader);
removeChild(termini_Loader);
it works perfectly... so is it possible to use removeChild
-
Senior Member
In which movie is this line:
termini.closebtn.addEventListener(MouseEvent.CLICK , function()
- The right of the People to create Flash movies shall not be infringed. -
-
-
Senior Member
This is what you need to have in your loaded swf:
function lHandler(e:Event):void
{
var myClip:MovieClip = e.currentTarget.parent as MovieClip;
if(MovieClip(myClip.parent.parent.root) != null)
{
MovieClip(myClip.parent.parent.root).removeChild(L oader(myClip.parent.parent));
}
}
termini.mc1.addEventListener(MouseEvent.CLICK, lHandler);
- The right of the People to create Flash movies shall not be infringed. -
-
Works
but i want to understand what it do exactly
PHP Code:
var myClip:MovieClip = e.currentTarget.parent as MovieClip;
my MovieClip is the entire "termini" movieclip, right?
but myClip.parent.parent.root i don't understand at what refers to
and in any case, if i want to climb up until the root, isn't more correct write "(root as MovieClip).getChildByName("..... " ) ?
-
myClip ---> refers to termini
myClip.parent ---> refers to loader initialized in the principal swf
myClip.parent.parent ---> refers to root of the principal swf
myClip.parent.parent.root ----> ?????
-
Senior Member
myClip is just one shortcut to avoid writing out everything. Important is myClip.parent.parent.root, because it refers to the main timeline of the parent movie and holds the Loader. From there you can remove the Loader. You should avoid getChildByName if you can, because it is not the actual id of the clip. The best is if you use trace(something) to see what the actual objects
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|