A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Load and remove an external SWF.. i've a problem to remove it

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    14

    Exclamation 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?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    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

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    external

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  7. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    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("..... " ) ?

  8. #8
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    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 ----> ?????

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center