as3 FlashEff changes displaylist

Posted by thengeveld 
as3 FlashEff changes displaylist
November 20, 2008 11:48PM
Hi all,

got everything working, just got a question about something that is happening. found a workaround though, but would be happier without the workaroud :)

Here's my situation which i think can be simplified to this:

I dynamically load a bunch of movieclips and add them with a timer interval to a movieclip container in the stage. Because of the timer interval the movieclips sort of 'popup' nicely. My script takes care of the x, y and childIndex properties to place all the movieclips correctly in the container.

To increase the nice popup effect when adding the movieclips to the stage, i decided to use the FESScale effect with a Bounce set as TweenType. This all works fine and all the movieclips scale/bounce into the container.

But i've noticed that my movieclips in fact are not present anymore in the container, but have been added to the FlashEff() instance of the show transition. These instances, with my movieclips inside, are now in the container (i think).

This is kinda annoying since for instance setChildIndex(movieclip, container.numChildren-1) to move a certain movieclip to the top of the container will not work anymore. This is because my MouseEvent.ROLL_OVER handler was already set on my movieclips. Since the movieclips are now added to the FlashEff instance, the swapping is done inside this FlashEff instance and does not place it above the other movieclips.

I hope some simplified code will makes this long story a little clearer:

########################################################
########### WITHOUT FLASHEFF
########################################################

var myList; // this is an array with all my movieclips i'm going to add to the container. each movieclip already has it's x,y properly set

var myTimer = new Timer(50); // fire every 50 milliseconds
myTimer.addEventListener(TimerEvent.TIMER, timerHandler, false, 0, true);
myTimer.start();

function timerHandler(event:TimerEvent):void
{
container.addChild(myList.pop());
}


########################################################
########### WITH FLASHEFF
########################################################
var myList; // this is an array with all my movieclips i'm going to add to the container. each movieclip already has it's x,y properly set

var myTimer = new Timer(50); // fire every 50 milliseconds
myTimer.addEventListener(TimerEvent.TIMER, timerHandler, false, 0, true);
myTimer.start();

function timerHandler(event:TimerEvent):void
{
var mc = container.pop(); // get the movieclip to work with
container.addChild(mc ); // FlashEff needs the mc to be added to the container displaylist

var showPattern:FESScale = new FESScale(); // create FESScale instance
var myShowEffect:FlashEff = new FlashEff(); // create FlashEff instance

container.addChild(myShowEffect); // add to container, else all hell breakes loose

myShowEffect.showTransition = showPattern; // set pattern
myShowEffect.showDelay = 0;
myShowEffect.showAutoPlay = true;
myShowEffect._targetInstanceName = mc.name;
//myShowEffect.target = mc; // _targetInstanceName and target both work.

showPattern.tweenDuration = 1;
showPattern.tweenType = "Bounce"
showPattern.easeType = "easeOut"
showPattern.preset = 1;
showPattern.maxBlur = 10;
}


########################################################
########### explanation
########################################################

Without the FlashEff everything works fine. the movieclips are at the right location, listen to all the right eventListeners set to them and i can swap them to the top of the container.

The version with the flashEff animation seems to add the mc to the myShowEffect instance. This is based on myShowEffect.getChildAt(1) suspiciously looks a lot like my mc :)

The mc itself have it's x and y properties reset to 0 (by FlashEff?), which makes sense, since they are now added to the myShowEffect instance.

########################################################
########### WITH FLASHEFF WORKAROUND
########################################################

all code stays the same, except add a transition_end listener in the timerHandler function for each mc being added / animated by FlashEff. (CallBack.create gives the possibility to add extra params to an eventListener):

myShowEffect.addEventListener(FLASHEFFEvents.TRANSITION_END, Callback.create(transitionEndHandler, mc), false, 0, true);

function transitionEndHandler(evtObj:FLASHEFFEvents, mc):void
{
// place mc back at original position. origX and origY were set when the myList was filled
mc.x = mc.origX;
mc.y = mc. origY;
container.addChild(mc); // addChild removes the mc from the myShowEffect instance and places it back at the container
}



Hope this complex story makes some sense. Is it possible to have FlashEff animations restore everything in the displaylist as they were?

Kind regards,
Tim

ps. please ignore if this example code might not work. i've stripped a bunch of other code to simpify. as said before, everying works perfect with the workaround
Re: as3 FlashEff changes displaylist
November 21, 2008 07:56AM
Indeed, a complex story, but I got the idea.

Your assumption is correct: FlashEff takes the target object and places it inside it's own container so it can make any necessary changes that the effect requires. So as long as the FlashEff instance is applied, the target object (movie clip or text field) will change its parent in the display list from the original parent to a FlashEff container. During that time you can access the actual reference of the target object through the target property of FlashEff.

The solution to your problem is wither to remove FlashEff from the clip, once the effect is over or simply use the setChildIndex() method directly on the FlashEff instances (which would probably be the easiest solution). In the case of removing FlashEff, you need to use the removeAll() method of FlashEff when the TRANSITION_END even is dispatched, but it will completely remove FlashEff and if you would like to use another effect or filter, then you would have to reapply FlashEff.
Re: as3 FlashEff changes displaylist
November 21, 2008 08:40AM
Hi Negush,

Thanks for confirming my assumptions (and so quickly). Took some research, but now i got a good idea whats going on.

Since the movieclips i want to animate into the stage are part of larger program, i will remove them from the flasheff container to restore their original functionality, this because already a lot of coding took place on these clips before adding them to the container. I will clean up the FlashEff references and containers for the sake of memory reuse / garbage collection.

Since the number of movieclips might grow quite large in numbers, i have a follow up question. You mentioned removing the FlashEff needs me to create a new instance again if i want to apply a new effect. What is more memory efficient. Deleting the FlashEff from every movieclip and create a new FlashEff when needed, or just keep one per movieclip as a reference which can be used lateron for new effects?

I haven't coded that much yet with FlashEff, but i presume i can just create a new Pattern and set the correct properties on the FlashEff to 'reset' the FlashEff to the new animation?

Kind regards,
Tim
Sorry, you do not have permission to post/reply in this forum.