Flash event handling – desktop apps vs mobile apps – Part 2

To cater for the touch interface of smartphones and tablets, Flash AS3 has a full list of touch events that coders can use. To program for touch based devices, it is sometimes easy to simply replace what you would normally use the mouse events with similar touch events like below:

MouseEvent.CLICK – TouchEvent.TOUCH_TAP

MouseEvent.MOUSE_DOWN – TouchEvent.TOUCH_BEGIN

MouseEvent.MOUSE_UP – TouchEvent.TOUCH_END

For example, see the following code comparing how to handle button click in a mouse based device (like computer) vs touch based device (like smartphone):

Mouse Based AS3 Code –

import flash.events.MouseEvent;

flash_btn.addEventListener(MouseEvent.CLICK, doWEB);

function doWEB(e:MouseEvent):void
navigateToURL(new URLRequest(“http://www.adobe.com/go/flash“));

Touch Based AS3 Code –

import flash.events.TouchEvent;

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

flash_btn.addEventListener(TouchEvent.TOUCH_TAP, doWEB);

function doWEB(e:TouchEvent):void
navigateToURL(new URLRequest(“http://www.adobe.com/go/flash“));

While you can use MouseEvent for touch-based devices, the advantage of using TouchEvent is that it supports multi-touch so you can have more than one button be responding simultaneously. As shown above, learning how to code for touch based devices is easy once you are familiar with the AS3 event handling. But that is not all, Flash AS3 also support gesture based events. More details can be found at the AS3 reference guide.


~ by brianchau on January 28, 2011.

7 Responses to “Flash event handling – desktop apps vs mobile apps – Part 2”

  1. The good site very interesting!!! Write to a thicket, it is pleasant to me!

  2. I’ve heard that there are performance differences between the two. If you use a MouseEvent and run it on a device, such as a phone, when you tap the fps goes down a lot. Never done any research on it tough.

  3. That’s true. If you try to move a sprite while you hold a button it slows down, And if you try to jump at the same time it slows down even more… Flash only allow fast taps without frame rate loss. There is a problem with moultitouch that I can’t fix. I can’t find a solution in google. May be, an android layer above de game. Can you post some help?.

  4. really cool…., thankyou very much……, keep ur good work 😉

  5. can we test touch API in non touch device ? I don’t have Touch device right now and want to test Touch API for my application. So need to test and debug in my laptop..


  6. is there any method to find out all the touch event code to replace mouse event? those move_out & hover are quite confusing..thanks..=)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: