{"id":583,"date":"2012-11-10T07:31:50","date_gmt":"2012-11-10T07:31:50","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=583"},"modified":"2012-11-13T16:13:06","modified_gmt":"2012-11-13T16:13:06","slug":"multi-touch-handling-in-air-for-androidios","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2012\/11\/10\/multi-touch-handling-in-air-for-androidios\/","title":{"rendered":"Multi-touch handling in AIR for Android\/iOS"},"content":{"rendered":"<p>To handle multitouch in AIR you need to  listen to <a href=\"http:\/\/help.adobe.com\/en_US\/FlashPlatform\/reference\/actionscript\/3\/flash\/events\/TouchEvent.html\" title=\"Adobe ActionScript reference - TouchEvent\">TouchEvent<\/a> events like <code>TouchEvent.TOUCH_BEGIN<\/code>. Which event you will listen depends on the <code>Multitouch.inputMode<\/code> defined, possile values are enumerated in <a href=\"http:\/\/help.adobe.com\/en_US\/FlashPlatform\/reference\/actionscript\/3\/flash\/ui\/MultitouchInputMode.html\" title=\"Adobe ActionScript reference - MultitouchInputMode\">MultitouchInputMode<\/a> class. We will use <code>MultitouchInputMode.TOUCH_POINT<\/code> which <em>specifies that events are dispatched only for basic touch events, such as a single finger tap<\/em>.<\/p>\n<p>It would be also good to make sure that we have touch enabled device or if we have enough number of touch points recognised, this information can be fetched from <a href=\"http:\/\/help.adobe.com\/en_US\/FlashPlatform\/reference\/actionscript\/3\/flash\/ui\/Multitouch.html\" title=\"Adobe ActionScript reference - Multitouch\">Multitouch<\/a> class.<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\r\nvar m_oTouchIDs:Object;\r\n\r\nif(Multitouch.supportsTouchEvents)\r\n{\r\n    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;\r\n    m_oTouchIDs = { };\r\n    \/\/we have touch screen\r\n    stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);\r\n    stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);\r\n    stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);\r\n}\r\n\r\nprotected function onTouchMove(e:TouchEvent):void \r\n{\r\n    \/\/update\r\n    var p:Point = m_oTouchIDs[e.touchPointID] as Point;\r\n    p.x = e.localX;\r\n    p.y = e.localY;\r\n}\r\n\t\t\r\nprotected function onTouchEnd(e:TouchEvent):void \r\n{\r\n    delete m_oTouchIDs[e.touchPointID];\/\/release\r\n}\r\n\r\nprotected function onTouchBegin(e:TouchEvent):void \r\n{\r\n    m_oTouchIDs[e.touchPointID] = new Point(e.localX, e.localY);\r\n}\r\n\r\n\r\n<\/pre>\n<p>Than you have an object containing position (and it could contain other details if needed) of each touch point which could be later used e.g. in a loop to verify what was &#8220;clicked&#8221;.<\/p>\n<p>best regards<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To handle multitouch in AIR you need to listen to TouchEvent events like TouchEvent.TOUCH_BEGIN. Which event you will listen depends on the Multitouch.inputMode defined, possile values are enumerated in MultitouchInputMode class. We will use MultitouchInputMode.TOUCH_POINT which specifies that events are &hellip; <a href=\"https:\/\/greladesign.co\/blog\/2012\/11\/10\/multi-touch-handling-in-air-for-androidios\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[47],"tags":[50,211,210],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/583"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":9,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":592,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions\/592"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}