|
-
Using MouseEvent and KeyboardEvent on the same function
I currently have an AS3 fla with a couple of mouseEvent functions but now the client wants to add a KeyboardEvent as well to the same exact functions. Can I add another eventListener to that without having to create a second function? It would be a huge waste of code if I did. Here's what I currently have in truncated form:
rightArrow.addEventListener(MouseEvent.CLICK, slide_right);
leftArrow.addEventListener(MouseEvent.CLICK, slide_left);
function slide_right(e:MouseEvent):void {
// Code goes here
}
function slide_left(e:MouseEvent):void {
// Code goes here
}
Adam Bell
[email protected]
--
Over 90% of all websites
suck......
Join the minority.
-
Yes. Just change your event arg datatype to the following:
PHP Code:
function slide_right(e:Event):void { // Code goes here }
function slide_left(e:Event):void { // Code goes here }
-
OK, I'll try that. But where do I add the event listeners for the keyboard events? Which in this case would be the right and left arrow keys respectively for the slide_right and slide_left functions. Would I place those underneath the other two addEventListener objects or inside of the functions themselves? I would think underneath the other two event listeners but I just want to confirm it. Thanks.
Adam Bell
[email protected]
--
Over 90% of all websites
suck......
Join the minority.
-
You can place them under the other two event listeners you have declared.
-
Do I add it like this?
stage.addEventListener(KeyboardEvent.KEY_DOWN, slideRight);
stage.addEventListener(KeyboardEvent.KEY_DOWN, slideLeft);
I've been reading through a bunch of different tutorials to figure out how to do this and this is the closest I've found although I'm still confused as to how to target the left and right arrow keys to enable the functions.
Adam Bell
[email protected]
--
Over 90% of all websites
suck......
Join the minority.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|