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?
Extending Event is only really necessary if you want to add some extra properties to it, for example:
So that when you dispatch this event from an enemy you can go:
And then make use of the
scoreproperty from the listening method within the game engine: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: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_FRAMEisn’t the case anyway, because they arestaticand belong to Event. You’ll get this error if you try accessENTER_FRAMEthrough the example in your answer: