Be a Supporter!

AS3 event handling

  • 278 Views
  • 8 Replies
New Topic Respond to this Topic
<deleted>
AS3 event handling May. 20th, 2010 @ 06:50 PM Reply

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)
{
	

}
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS3 event handling May. 20th, 2010 @ 07:17 PM Reply

u r a retart.


wtfbbqhax

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to AS3 event handling May. 20th, 2010 @ 07:25 PM Reply

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.

<deleted>
Response to AS3 event handling May. 20th, 2010 @ 07:31 PM Reply

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?

Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to AS3 event handling May. 20th, 2010 @ 07:43 PM Reply

Don't waste your time on this.


BBS Signature
meneldil
meneldil
  • Member since: May. 27, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS3 event handling May. 20th, 2010 @ 08:20 PM Reply

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


Indescriptive topic names have left me in despair!

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to AS3 event handling May. 20th, 2010 @ 08:45 PM Reply

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.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS3 event handling May. 21st, 2010 @ 03:48 AM Reply

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?)

JoSilver
JoSilver
  • Member since: Sep. 21, 2007
  • Offline.
Forum Stats
Member
Level 16
Melancholy
Response to AS3 event handling May. 21st, 2010 @ 04:19 AM Reply

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!