Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4254458
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:05:12+00:00 2026-05-21T05:05:12+00:00

I am always trying to improve my programming practices and this one habit of

  • 0

I am always trying to improve my programming practices and this one habit of mine has gotten me thinking that maybe it isn’t the best approach. When handling MouseEvent function calls I have a tendency to use Event over MouseEvent in the params.

Example:

mc.addEventListener(MouseEvent.CLICK, handleClick);

private function handleClick(e:Event):void
{
     trace(e.currentTarget.name + " was Clicked");
}

Is there some functionality or properties inside of MouseEvent unavailable in the Event class that would make using MouseEvent more of a necessity? The only reason I can think of on my own is to keep your events/functions params strongly-typed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:05:13+00:00Added an answer on May 21, 2026 at 5:05 am

    If you don’t type the parameter as MouseEvent, you will just have to cast it as a MouseEvent to access properties that are specific to the MouseEvent subclass. For example:

    This won’t work:

    private function handleClick(e:Event):void
    {
         trace("altKey down: "+e.altKey);
    }
    

    But this will:

     private function handleClick(e:MouseEvent):void
     {
         trace("altKey down: "+e.altKey);
     }
    

    However so will this (not recommended though, see below):

     private function handleClick(e:Event):void
     {
         trace("altKey down: "+MouseEvent(e).altKey);
     }
    

    Generally speaking, you want your listener parameter type to be only as general as is necessary, so that if your function is called with the wrong type of event, it fails in an obvious way.

    Your example works because currentTarget is a property of the Event base class. But there is nothing stopping your handleClick from receiving and responding to an IOErrorEvent or KeyboardEvent, and doing something you don’t expect without failing (e.g. if you accidentally set it up to listen to something other than a MouseEvent, which you would not do deliberately, but could happen if you copy-paste the addEventListener line of code and change the event type but forget to change the handler function… these things do happen).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to validate that an element always has an href attribute in RelaxNG,
I always get this error when trying to compile my file with Boost::GIL PNG
I am trying to get a footer that will always stay at the bottom
I'm trying to get this running: JAXB interface But I always get the error
I am trying to get a layout that always takes up the entire screen,
OK, I'm always trying to improve the way I code, because it's my passion.
I'm trying to improve perf in an app that uses Linq2Sql heavily. I have
I'm trying to (slightly) improve a script that does a quick-and-hacky parse of some
I find myself always trying to fit everything into the OOP methodology, when I'm
I am trying to have a content block always be shown to the user,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.