Results 1 to 8 of 8
Thread: Tweenlite keeping reference?
-
August 17th, 2009, 11:43 AM #1175Registered User
postsTweenlite 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.
-
August 17th, 2009, 12:16 PM #251Yes, its me
postsDid 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"));
}
-
August 17th, 2009, 12:45 PM #3175Registered User
posts>>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.
-
August 17th, 2009, 12:56 PM #4175Registered User
postsYeesh... 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...
-
August 17th, 2009, 04:00 PM #5Code:
TweenLite.to(detail, .5, { alpha:0, onComplete:removeFromDisplayList, onCompleteParams:[detail] } ); public function removeFromDisplayList(displayObject:DisplayObject):void { if (displayObject.parent) displayObject.parent.removeChild(displayObject); }
-
December 18th, 2009, 10:57 AM #61Registered User
postsThis 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!
-
January 2nd, 2010, 04:26 PM #71Registered User
postsThis 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);
-
January 3rd, 2010, 02:36 PM #8

Reply With Quote
isplayObject):void {

Bookmarks