A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: evt.target question

  1. #1
    absolutezero3424
    Join Date
    Nov 2006
    Posts
    508

    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!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center