Call: (209) 560-6611

Touch Event AS3 simple example

Date: August 18, 2014 Author: ang Category: Tutorials Comments: 0

In this tutorial I will show you how to create a simple touch event app using FlashCC and ActionScript.

Simple touch event using AS3

  1. Open FlashCC and click 'File' > 'New' > 'AIR for Android'..
  2. Click 'File' > 'Save', and save the document as 'Main'.
  3. Input 'Main' in the 'Class:' field and click the pencil icon next to it.
  4. 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.'
  5. Click the pencil icon again next to the 'Class' field.
  6. Select 'Flash Professional' and click 'OK' on the popup window that pops up.
  7. 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
  8. Click 'File' > 'Save' and save this project class to the same directory as the '.fla' file.
  9. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Before you post, please prove you are sentient.

what is 7 + 4?

Before you post, please prove you are sentient.

What color is the sky on a sunny day?