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 6959537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:17:05+00:00 2026-05-27T15:17:05+00:00

I would like to extends the Event class to add some events I am

  • 0

I would like to extends the Event class to add some events I am using in game.
But I don’t want the new Event Class to have the old public static types..
For instance I don’t want to have:

NewEventClass.ENTER_FRAME

How do you go about extending the Event class without getting the old types mixed in?

Is there any way to outsmart AS3 to leave out the uneeded types?

Or should I avoid creating a new Event type altogether and just add the new strings?

  • 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-27T15:17:06+00:00Added an answer on May 27, 2026 at 3:17 pm

    Extending Event is only really necessary if you want to add some extra properties to it, for example:

    public class EnemyEvent extends Event
    {
        // Constants used to represent event type
        public static const ENEMY_KILLED:String = "killed";
    
        // Event properties
        public var score:int = 0;
    
        /**
         * Constructor
         * Retain Event behaviours
         */
        public function EnemyEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
        {
            super(type, bubbles, cancelable);
        }
    }
    

    So that when you dispatch this event from an enemy you can go:

    var evt:EnemyEvent = new EnemyEvent(EnemyEvent.ENEMY_KILLED);
    evt.score = myScoreValue;
    
    dispatchEvent(evt);
    

    And then make use of the score property from the listening method within the game engine:

    enemy.addEventListener(EnemyEvent.ENEMY_KILLED, _countKill);
    function _countKill(e:EnemyEvent):void
    {
        gameTotalScore += e.score;
        if(gameTotalScore > 100) getAchievement();
    
        e.target.removeEventListener(e.type, _countKill); // <-- woudn't work without extending event either
    }
    

    If you just need to store constants to use in addEventListener(x, ..), new Event(x), etc then you can just make a class that holds these and doesn’t have anything to do with Event:

    public class CustomEvents
    {
        public static const MY_CUSTOM_EVENT:String = "myCustomEvent";
    }
    

    So that you can just use these as needed:

    • new Event(CustomEvents.MY_CUSTOM_EVENT);
    • addEventListener(CustomEvents.MY_CUSTOM_EVENT, _listener);

    The former method is still preferable as it’s tidier and more logical.

    Additionally; your note about your custom event having constants such as ENTER_FRAME isn’t the case anyway, because they are static and belong to Event. You’ll get this error if you try access ENTER_FRAME through the example in your answer:

    1119: Access of possibly undefined property ENTER_FRAME through a
    reference with static type Class.

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

Sidebar

Related Questions

I have a game here, and I would like to add event handlers to
I have a custom-made view that extends the View class. I would like 2
I'm trying to extend my ActiveRecord class with some dynamic methods. I would like
I would like to extend a kd-tree (2D) class to be able to remove
I would like to create extend a Java Swing application to have a look
I have an application that calls AlarmManager Intent intent; intent = new Intent(context, MyEventReceiver.class);
I would like to make Canvas area transparent because I would like to add
I have created a class called SimpleCanvas which extends the JPanel class, and I
I have a system that manages events that happen to multiple actors using a
I would like to add elements to a list box on a jframe, from

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.