1

I'm working on something right now to have a function that creates almost any graphic or special effect I could imagine (granted I have a base movieClip or two) and I've run into a problem. I need to be able to add functions to the effect movieClip based on paramaters passed into the GraphicEffect functions behaviors object. Is there an effective way to add new functions such as spin, grow, shrink etc. to an already existing onEnterFrame function without having if-statements placed inside?

2 Answers 2

2

Yes, there is a way.

I'm not sure how you have your behaviors object set up, but assuming it is something like {A:spin,B:grow,C:fade} you can implement an addition of functions to your effect movieclip (I'll just call it 'fx') by using the following style of code:

   fx.TempA=fx.onEnterFrame;
   function NewA(){fx.TempA();behaviors.A(fx);};
   fx.onEnterFrame=function(){NewA();};   
   fx.TempB=fx.onEnterFrame;
   function NewB(){fx.TempB();behaviors.B(fx);};
   fx.onEnterFrame=function(){NewB();};   
   fx.TempC=fx.onEnterFrame;
   function NewC(){fx.TempC();behaviors.C(fx);};
   fx.onEnterFrame=function(){NewC();};
Sign up to request clarification or add additional context in comments.

Comments

0

A different way

mcFX.enterFrameFunctions = [];

mcFX.onEnterFrame = function(){
    for(var i in this.enterFrameFunctions) this.enterFrameFunctions[i]();
}

function a():Void {
    trace("a called");
}

function b():Void {
    trace("b called");
}

function c():Void {
    trace("c called");
}

mcFX.enterFrameFunctions.push(a, b);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.