Hmm, I didn't know about that scope chaining stuff, thanks for the link.
One question, does the chaining (specifically, the activation object stuff when using inner functions) still apply to AS2 code? I use functions like that for listeners in a *lot* of places, and now I'm worried it's wasting a lot of memory. -Andy On 2/20/07, Jesse Graupmann <[EMAIL PROTECTED]> wrote:
Mike - True, for this example. Felipe - Not sure you can get around the eval or Delegate unless you add a ton of array notation. There is a good article to describe this; Scope Chain and Memory waste in Flash MX: http://timotheegroleau.com/Flash/articles/scope_chain.htm. So eval or moreEvil? That is the question... function runMe () { trace( this + ' run me' ) } _global.moreEvil = function( str:String ):Function { var array = str.split ( "." ) ; var func = _root; var len = array.length; for ( var i = 0; i < len; i ++ ) { func = func [ array [ i ] ] ; if ( i < len - 1 ) var scope = func; } if ( scope == undefined ) var scope = _root; return function(){ func.apply ( scope, arguments ) }; } var myFunction = moreEvil ( "_root.runMe" ); myFunction (); _____________________________ Jesse Graupmann www.jessegraupmann.com www.justgooddesign.com/blog/ _____________________________ -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Felipe Hefler Sent: Monday, February 19, 2007 6:57 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] Passing a Function as Parameter and callfunctionlater Thank you all guys! Great job. But I still have something to ask, silly or not. One thing eval does for me and I don't know if I'm right or wrong, is when I use it (despite I know it's not the better solution), it let's me leave my function like this: _anywhere.rew(mcToRewind, whenDoneRewindingNewAction); ^ path.MC ^ same path of mcToRewind Why this is matter to me? Because I don't have to treat the scope as a parameter and I can keep my function easy to use for any newbie/flash designer (that is really important to me). So nobody doesn't have to think about scope stuff and anybody can use it as was using a very common function. Which using your code they have to think about scope, putting all the path as a different parameter. In Jesse's third example we could just drop the scope parameter. However, it's always treating the scope from where the function is. While this is perfectly right and understandable for me I think a newbie would spend I time to understand what's going on. If I've been nagging to much or the real stupid one, we can just drop the subject, and stick to your solutions. = P On 19/02/07, T. Michael Keesey <[EMAIL PROTECTED]> wrote: > > On 2/18/07, Jesse Graupmann <[EMAIL PROTECTED]> wrote: > > var callback:Function = mx.utils.Delegate.create ( _root, nextFrame ); > > anyOtherObject.func = function(){ callback () }; > > anyOtherObject.func (); > > You can combine the first two lines (and simplify the second) to just: > > anyOtherObj.func = mx.utils.Delegate.create(_root, nextFrame); > > No need for the inline function. > -- > Mike Keesey > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
_______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com