The web site for Flash ActionScript 3.0 game developers

 
         
   

Using functions for multiple events and faking a mouseclick event.

I have two issues I haven't been able to find information on even after a lot of searching online. Both are related to the fact that functions seem to be tied to only one kind of event and sometimes you would like them to occur in either of two possibilities.

1. How do you take a function that is designed for reacting to a click on a button and have it also respond to a keypress? The example would be your Trivia game. How do you make the buttons also take a key as the selection for the answer?

2. I have added a timer function to the Trivia game and would like the game to take a failure to respond in time as an incorrect answer. The easiest way is to call ClickAnswer(), but it is expecting only Clicks, right? "public function clickAnswer(event:MouseEvent)" Is there some way to fool the program into thinking a click was given when the Timer has hit its end? Or can you define functions to respond to multiple sources? It seems inefficient to write two functions, one for each kind of event.

Thanks in advance.



Copyright Gary Rosenzweig