Correct way to cleanup after Text effect completed

Posted by user835016 
Correct way to cleanup after Text effect completed
July 30, 2012 11:41AM
I have a text effect that is correctly playing my show transition (once only, I don't want looping), but in the transition end event handler I want to cleanup everything that was added to my component for the text effect (ie. the FlashEff2Flex instance). When I removeChild() on the FlashEff2Flex effect instance, my text hides. I've tried calling show and removeAll before removeChild but that didn't help. Why does calling removeChild cause my text to hide?
Re: Correct way to cleanup after Text effect completed
July 30, 2012 01:32PM
That's because now FlashEffFlex instance contains the textfield at that point. Make sure that before you call removeChild you are calling removeAll and the target is set to null.
Re: Correct way to cleanup after Text effect completed
July 30, 2012 02:38PM
Still not working. Here is the code from my transition end event handler. textEffect is the FlashEff2Flex instance.

textEffect.removeAll();
textEffect.target=null;
removeChild(textEffect);

It only works if I force set the visible property of the target.

textEffect.removeAll();
removeChild(textEffect);
textEffect.target.visible=true;
textEffect.target=null;

Actually in both cases setting textEffect.target to null didn't make any difference. It was the force setting of target to visible that stopped the target being hidden. Why is FlashEff doing this?



Edited 1 time(s). Last edit at 07/30/2012 02:46PM by user835016.
Re: Correct way to cleanup after Text effect completed
August 01, 2012 12:40PM
Well, FlashEff is hiding the target because a hide effect was applied. FlashEff is doing that automatically.
Re: Correct way to cleanup after Text effect completed
August 02, 2012 03:11AM
No hide transition was set, only a show transition. Furthermore, the hide occurs when the textEffect is removed from the parent. I believe this behavior is incorrect. Even setting the textEffect target to null before removeChild made no difference. I'm building a standalone test app to prove that there is an issue here and will log a support case.

Edit: I believe I have the answer.

To create the effect:
myEffect=new FlashEff2Flex();
myEffect.target=txtMessage.mx_internal::getTextField();
myEffect.isTargetVisibleAtEnd=true;
myEffect.showTransition=textShowEffect;
myEffect.addEventListener(FLASHEFFEvents.TRANSITION_END, effectEnding);
addChild(myEffect);

To remove the effect from scope:
private function effectEnding(evt:FLASHEFFEvents):void
{
trace("The effect has endded");
myEffect.removeAll();
removeChild(myEffect);
}

Doing it this way results in the target text no longer being hidden once the effect has completed. It would be nice if this was documented somewhere.



Edited 1 time(s). Last edit at 08/02/2012 07:57AM by user835016.
Re: Correct way to cleanup after Text effect completed
August 02, 2012 12:39PM
See my first post:
"That's because now FlashEffFlex instance contains the textfield at that point. Make sure that before you call removeChild you are calling removeAll and the target is set to null."
Basically the code would look like this:

myEffect.target=null;
myEffect.removeAll();
removeChild(myEffect);

Anyway, when you are applying flasheff on a target that target will be placed within FlashEff instance. Therefore in order to come to the initial state you need to remove the FlashEff instance from the target. That's what removeAll method should do.

PS We've made some update to Flex package, so now it should work on 4.5 and 4.6 version properly without any workaround. Also there were some changes regarding the remove of the instances and objects in certain scenario. You should re-download the package and use the new swc files.
Re: Correct way to cleanup after Text effect completed
August 03, 2012 08:15AM
Actually what made it work for me was:
myEffect.isTargetVisibleAtEnd=true;

Without that, the target was still being hidden. Will try the new SWCs and see if that changes anything.
Sorry, you do not have permission to post/reply in this forum.