00:00
00:00
Newgrounds Background Image Theme

Em0-Snail just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS3 event handling

525 Views | 8 Replies
New Topic Respond to this Topic

AS3 event handling 2010-05-20 18:50:04


What I am trying to do is have one function handle every event in AS3. Why? Personally, I think it would be easier for me to manage. All I need to do now is when the function eventHandle is executed, have it check which event is being called using a switch statement. Is this possible? How can I check which event is being called?

import flash.events.Event;

stage.addEventListener(Event.ENTER_FRAME,eventHandle);
stage.addEventListener(Event.EXIT_FRAME,eventHandle);
stage.addEventListener(Event.KEY_DOWN,eventHandle);
stage.addEventListener(Event.KEY_UP,eventHandle);

function eventHandle(event)
{
	

}

Response to AS3 event handling 2010-05-20 19:17:17


u r a retart.


wtfbbqhax

Response to AS3 event handling 2010-05-20 19:25:09


At 5/20/10 07:17 PM, fwe wrote: u r a retart.

Funny :). But if he wants to do it, who are we to stop him :P. The event class has a property "type". This is what you are looking for. Have fun :).


You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

Response to AS3 event handling 2010-05-20 19:31:21


What is so bad about this method that makes you give such a reaction? I'm betting it's like the whole coding on Movie Clips thing! Seriously, if the code works as I want it to and I can modify it easily, why should I worry if it isn't exactly the most accepted approach?

Response to AS3 event handling 2010-05-20 19:43:12


Don't waste your time on this.


BBS Signature

Response to AS3 event handling 2010-05-20 20:20:34


This is going to cost you more CPU than the normal way.


Indescriptive topic names have left me in despair!

Response to AS3 event handling 2010-05-20 20:45:55


Well think about for a second what you are doing there. You want to listen to all events all the time. This means that your function will be run many times per frame. I guess it's going to take a lot of CPU power. And there is also the fact that you aren't using the event system like it was meant to be used. There are many different events so you use them for their purposes, not just run them all at the same time all the time.


You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

Response to AS3 event handling 2010-05-21 03:48:37


At 5/20/10 07:31 PM, SmartNoob wrote: What is so bad about this method that makes you give such a reaction?

Did you even think about it?
You make a decision on which handler function to call, then you throw the result of the decision away by calling the same function, just to finally decide again?

You can register the same handler function on multiple objects with the same event, when the objects do the same, but you idea is bad.

I'm betting it's like the whole coding on Movie Clips thing! Seriously, if the code works as I want it to and I can modify it easily, why should I worry if it isn't exactly the most accepted approach?

I guess you then better keep coding on Movieclips in AS2. (Did I ever mention what I think about people in the forums that just do not want to take an advice?)

Response to AS3 event handling 2010-05-21 04:19:00


BAWWWHAHAHA!!! Wut kinda stupidity is that THAT!

Stop coding if this is your approach.

1.That's just a dumb Idea.
2. making more then one function will make things simpler.

Just make more then one function. The reason you can is so you don't have to do that!