The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 8 of 8

Thread: Tweenlite keeping reference?

  1. #1

    Tweenlite keeping reference?

    Having a little issue with TweenLite seemingly keeping a reference to my clip. In one method I do:

    detail.btnBack.addEventListener(MouseEvent.CLICK, removeDetail, false, 0, true);

    Then I have the removeDetail, and killDetail methods:

    private function removeDetail(e:MouseEvent):void
    {
    TweenLite.to(detail, .5, { alpha:0, onComplete:killDetail } );
    }

    private function killDetail():void
    {
    removeChild(detail);
    }

    This _seems_ to work, except the removeChild is not working - the detail clip is faded, and killDetail is called, but the clip remains. If I remove the TweenLite fade and do the removeChild right in removeDetail() the clip is fully removed from the display list. I've tried doing a TweenLite.killTweensOf(detail) within the killDetail(), before removing child on it, but that doesn't help.

    I can't recall ever having an issue like this with TweenLite before.

  2. #2
    Did you define the detail variable on the top?

    Try just putting the function in the tweenlight function
    private function removeDetail(e:MouseEvent):void
    {
    TweenLite.to(detail, .5, { alpha:0, onComplete:function killDetail(){
    remove Child(detail);
    } } );
    }

    ugly code..not best practice..
    Alternatively you can use getChildByName (make sure you name it, and know where it is, parent or inside a movieclip..)

    private function removeDetail(e:MouseEvent):void
    {
    TweenLite.to(detail, .5, { alpha:0, onComplete:killDetail } );
    }

    private function killDetail():void
    {
    removeChild(getChildByName("detail"));
    }

  3. #3
    >>Did you define the detail variable on the top?

    Yeah, or I couldn't have referenced detail in either of those methods. I won't use anonymous functions like that... and I'm not naming it, detail is an instance of a library clip, instantiated in the constructor. It does work as expected if I removeChild(detail) without fading it out, but I need it to fade first. For some reason using TweenLite with the onComplete is not allowing the removeChild to work.

  4. #4
    Yeesh... it was just me being daft.

    It was removing the child just fine. The problem was that I was fading out the entire detail clip - while my call to add it back in, faded in elements of the clip so as to build it in... but the main container still had its alpha at 0, so you couldn't see anything. Sometimes...

  5. #5
    Code:
    TweenLite.to(detail, .5, { alpha:0, onComplete:removeFromDisplayList, onCompleteParams:[detail] } );
    
    
     public function removeFromDisplayList(displayObject:DisplayObject):void {
      if (displayObject.parent) displayObject.parent.removeChild(displayObject);
     }

  6. #6
    1
    posts
    Registered User
    Quote Originally Posted by Felixz View Post
    ActionScript Code:
    TweenLite.to(detail, .5, { alpha:0, onComplete:removeFromDisplayList, onCompleteParams:[detail] } );


    public function removeFromDisplayList(displayObjectisplayObject):void {
    if (displayObject.parent) displayObject.parent.removeChild(displayObject);
    }
    This worked well for me... Thanks! Flash was throwing all kinds of errors at me when I was trying to delete the child from within the onComplete function itself.

    "Error #2025: The supplied DisplayObject must be a child of the caller."


    Your solution has fixed this! Thanks again!

  7. #7
    This code works for me as well, flash was complaining with errors that I couldn't figure out. Can you give a quick explanation as to what this line is doing:


    if (displayObject.parent) displayObject.parent.removeChild(displayObject);

  8. #8
    Quote Originally Posted by flashbearie View Post
    This code works for me as well, flash was complaining with errors that I couldn't figure out. Can you give a quick explanation as to what this line is doing:


    if (displayObject.parent) displayObject.parent.removeChild(displayObject);
    What that is saying, is that if the object you want to remove is contained within another object, meaning it has a parent and can be removed, then tell the parent of the object you want to remove to remove your object.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012