-
evt.target question
Is it wrong to do this?
Code:
some_mc.addEventListener(MouseEvent.CLICK, someAction);
function someAction(evt:MouseEvent):void {
evt.target.x = 100;
}
I've seen many people/tutorials that use an extra step like this:
Code:
some_mc.addEventListener(MouseEvent.CLICK, someAction);
function someAction(evt:MouseEvent):void {
var new_mc:MovieClip = evt.target as MovieClip;
new_mc.x = 100;
}
what is the advantage/benefit of adding the extra step? I'm guessing it has something to do with memory usage? just curious...thx!
-
1. You clearly cast the object as what it is, which makes it easier for the compiler. Occasionally you get errors if you don't do it.
2. It makes the expression smaller, just one value and easier to work with.