It certainly works if the type matches up, but it runs faster/is more optimized if you do strongly type myObj.
The other thing that would probably speed up execution is if you assign myObj.menuSquare_mc to a local variable. It takes more time to do the dot lookup on the item you're referencing each time than if you'd do the lookup once and use the local var to reference it. If you intend to reference a variable more than a few times, store it in a local var. You can do it the other way, but I've found it's a pretty good habit to get into as you don't have to change your methodology once you're working on projects that are iterating through a lot of data. The most obvious example is if you define a variable like "arrayLength" equal to array.length and use that in your for loop, you get a performance gain: var arrLength:uint = array.length; for(i:uint=0;i<arrLength;i++){ } //runs faster than for(j:uint=0;j<array.length;j++){ } This is because you're doing that dot lookup with each iteration in the second example. But I digress. The other benefit to this practice is if you're using a tool like Flex Builder or FDT or FlashDevelop or whatever, you can get code hinting on your now strongly-typed vars which can speed development, though less so in this case since you're passing TweenMax an object. Also with strong typing, the compiler will throw compile-time errors which shortens the debugging path. So here's how I'd do your example, I suppose: function leftmenu($e:MouseEvent ):void { var myObj:MovieClip = $e.currentTarget as MovieClip; //you don't necessarily have to use the 'as' part, but specificity is a bonus when you're passing these things around. var mySquare:MovieClip = myObj.menuSquare_mc as MovieClip; // or Sprite or whatever. switch($e.type){ case "mouseOver": TweenMax.to(mySquare, .3, {alpha:.06, delay:0,ease:Sine.easeOut}); TweenMax.to(myObj, .3, {x:60, delay:0, ease:Sine.easeOut}); TweenMax.to(mySquare, .3, {x:-60, delay:0, ease:Sine.easeOut}); break; case "mouseDown": trace(myObj.name <http://e.currenttarget.name/>); break; case "mouseOut": TweenMax.to(mySquare, .3, {alpha:0, delay:0, ease:Sine.easeOut}); TweenMax.to(myObj, .3, {x:30, delay:0, ease:Sine.easeOut}); TweenMax.to(mySquare, .3, {x:0, delay:0, ease:Sine.easeOut}); break; } --Matt On Tue, May 12, 2009 at 5:32 AM, <zu...@zadesigns.com> wrote: > This is the code I used to solve it. I used currentTarget, and I had my > movieclips already on stage, so I guess I didn't need to refrence them as > MovieClips? either way it works... do i need to set my type to the var > myObj? it works regardless. > > function leftmenu($e:MouseEvent ):void { > var myObj = $e.currentTarget; > trace($e.type + " : " +$e.currentTarget.name ) ; > if ($e.type == "mouseOver") { > TweenMax.to(myObj.menuSquare_mc, .3, {alpha:.06, > delay:0, > ease:Sine.easeOut}); > TweenMax.to(myObj, .3, {x:60, delay:0, > ease:Sine.easeOut}); > TweenMax.to(myObj.menuSquare_mc, .3, {x:-60, > delay:0, > ease:Sine.easeOut}); > } > if ($e.type == "mouseDown") { > trace($e.currentTarget.name); > } > if ($e.type =="mouseOut") { > TweenMax.to(myObj.menuSquare_mc, .3, {alpha:0, > delay:0, > ease:Sine.easeOut}); > TweenMax.to(myObj, .3, {x:30, delay:0, > ease:Sine.easeOut}); > TweenMax.to(myObj.menuSquare_mc, .3, {x:0, delay:0, > ease:Sine.easeOut}); > } > } > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders