1

I want to detect touchBegin event in Image component in Flex mobile but when I set <...touchBegin="myMethod()" /> , but its doesn't trigger when I touch that image.

Any ideas?

Zaur Guliyev
  • 4,254
  • 7
  • 28
  • 44

2 Answers2

2

The reason you might not be seeing any event triggered is that depending on the device, touchBegin might not be the event that gets triggered on the beginning of the touch, there seems to be some discrepancy on what devices use touchBegin and which ones use mouseDown.

For example to test this I used the put the following properties in an Image:

touchBegin = "touchBeginHandler(event)"
mouseDown = "mouseDownHandler(event)"

And the following code:

protected function touchBeginHandler(event:TouchEvent):void
{
    trace("Touched");
}

protected function mouseDownHandler(event:MouseEvent):void
{
    trace("Moused");
} 

On both the phone emulator and my actual phone the result was a trace statement of "Moused". So long story short, try using the mouse down event to see if you get your desired results.

Shastings
  • 167
  • 2
  • 12
  • But what if I want to catch touch moves as well? will mouse move work instead of this? p.s I haven't tried this all on real device as i'm developing using flex emulator.. – Zaur Guliyev Mar 19 '12 at 07:52
  • 1
    I set up handlers for the four events in question, touchBegin, touchMove, mouseDown, and mouseMove, and I'm not sure if it's just my device, but I didn't hit either of the touch events at all, I only got mouse events. This was both debugging in the emulator as well as debugging on my Droid 2. So it looks to me like the events you want to use are MouseEvents. – Shastings Mar 19 '12 at 19:13
1

I think you have to actually enable the multi touch gestures mode on mobile to get the touch events instead of mouse events.

http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/ui/Multitouch.html#inputMode

http://sujitreddyg.wordpress.com/2010/03/17/flex-4-application-handling-touch-events-on-android-with-flash-player-10-1/

shaunhusain
  • 19,630
  • 4
  • 38
  • 51
  • Is there any way to make "mouse clicks" to be caught as "touch"es? Or is it possible only using device? – Zaur Guliyev Mar 19 '12 at 07:50
  • @lbstr no not that I'm aware of, you can use Multitouch.supportsTouchEvents to determine if the device the app is being run on supports touch events. Touch events do not directly correspond in a one to one way with mouse events, they use a different string literal for their types and the events themselves carry different information, for example pressure and touchId which don't make sense in the context of mouse events. What is your goal, if you want to have touch enabled capabilities you'll have to test on a touch enabled device. – shaunhusain Mar 19 '12 at 17:24