A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] AS3 Any Cons with passing MouseEvents of different types to same handler function?

  1. #1
    Senior Member
    Join Date
    Jan 2006

    resolved [RESOLVED] AS3 Any Cons with passing MouseEvents of different types to same handler function?

    Hello All,

    I was just wondering if there are any problems that could arise from passing MouseEvents of different types (i.e. MouseEvent.CLICK or MouseEvent.MOUSE_DOWN) at different times to the same function?

    I've already built my project, and it seems to function fine, I just want to make sure that I'm not setting myself up for some problems in the future. I understand it's probably not the "cleanest" or "best practice" to construct my project in this manner, but if it works...

    A simplified example:

    PHP Code:
    // This is the function that I want to call from varying places with different MouseEvents and triggered by different event listeners
    function myFunctionA(evt:MouseEvent):void{
    // Do Some Stuff
    // Do some more stuff, etc.

    // Here's all my listeners
    Actually, in writing that, I may have answered my own question, because it seems that myFunctionA is simply expecting a MouseEvent... regardless if that event is CLICK or MOUSE_DOWN or MOUSE_UP event, right?

    Now, a MouseEvent.CLICK may have different properties than a MouseEvent.MOUSE_UP that I can access within myFunctionA; however, that shouldn't matter to the function, or is my thinking flawed?
    Last edited by badaboom55; 09-22-2009 at 08:39 PM.

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    There's no problem with that at all, it's actually meant to be reused. In fact, you can even call the function without a mouse event by passing null as a parameter.


    though, in that case there would be no event to reference.
    Search first, asked questions later.

  3. #3
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    San Francisco, CA (USA)
    If you want ButtonA_btn, HolderB_mc, or HolderC_mc, make sure you use e.currentTarget, not e.target

  4. #4
    Senior Member
    Join Date
    Jan 2006
    Thanks... I never tried passing NULL before...

    That's actually really helpful because there's been times where I've written a handler function that is usually triggered by a MouseEvent... but then the project specs change, and I end up needing to call the same handler function from something completely different... say a frame action (so I can't pass it a MouseEvent reference).

    It never occurred to me to send a "null" parameter... I guess because the way Flash requires all the strict data typing, I just figured sending a "null" parameter would get me the same error as sending no parameter at all (or a parameter not of a MouseEvent type)...

Tags for this Thread

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