In this tutorial I will show you how to create a simple touch event app using FlashCC and ActionScript.
Simple touch event using AS3
- Open FlashCC and click 'File' > 'New' > 'AIR for Android'..
- Click 'File' > 'Save', and save the document as 'Main'.
- Input 'Main' in the 'Class:' field and click the pencil icon next to it.
- Click 'OK' on the message that pos up saying 'A definition for the document class could not be found in the classpath, so one will be automatically generated in the SWF file upon export.'
- Click the pencil icon again next to the 'Class' field.
- Select 'Flash Professional' and click 'OK' on the popup window that pops up.
- You should see the 'Main' project class. Delete all the code in it, and replace it with this code.
Javascript | copy code | ? 01 package {
02 03 import flash.display.MovieClip;
04 import flash.events.TouchEvent;
05 import flash.ui.Multitouch;
06 import flash.ui.MultitouchInputMode;
07 08 //create vars
09 10 public class Main extends MovieClip {
11 12 13 public function Main() {
14 // constructor code
15 Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
16 stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
17 stage.addEventListener(TouchEvent.TOUCH_END, onTouchFinish);
18 }
19 20 function onTouchBegin(e:TouchEvent):void {
21 trace("touch on!!!");
22 }
23 24 function onTouchFinish(e:TouchEvent):void{
25 trace("touch off!!!");
26 }
27 28 }
29 30 }
31 - Click 'File' > 'Save' and save this project class to the same directory as the '.fla' file.
- Publish your project 'CTRL' + 'Enter' key'.
Now when you click the mouse on the Android simulator, you should see 'touch on!!!' and 'touch off!!!' when you press and release the mouse button.