# TouchEvent addEventListener

**URL:** https://forum.kirupa.com/t/touchevent-addeventlistener/305820
**Category:** flash
**Created:** [March 4, 2010, 3:58am UTC](https://forum.kirupa.com/t/touchevent-addeventlistener/305820 "2010-03-04T03:58:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![li1](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@li1](https://forum.kirupa.com/u/li1)
#### Post date: [March 4, 2010, 3:58am UTC](https://forum.kirupa.com/t/touchevent-addeventlistener/305820/1 "2010-03-04T03:58:29Z")

</div>

Hi All. I am looking for assistance with the following;

Products;  
F.Player 10.1 beta 3  
Flash Builder 4 Beta / CS4 Flash  
MS IE 8.  
EEEPC T91MT (touchscreen) Win 7.

issue;  
addEventListener only works once on  
“Multitouch.inputMode = Multitouch.InputMode.TOUCH\_POINT”  
(the event listener is only ‘listening’ once and then stopping)  
this applies to TOUCH\_TAP , TOUCH\_BEGIN, TOUCH\_MOVE, TOUCH\_END.

but using “Multitouch.inputMode = Multitouch.InputMode.GESTURE” allows me to touch the screen then stop touching and then touch again. (the event listener is picking up the touchevent)  
this applies to GESTURE\_ZOOM, GESTURE\_ROTATE

I am using the example code for \>\> Multitouch.inputMode = Multitouch.InputMode.TOUCH\_POINT

package  
{  
import flash.display.Sprite;  
import flash.events.TouchEvent;  
import flash.text.AntiAliasType;  
import flash.text.TextField;  
import flash.text.TextFormat;  
import flash.ui.Multitouch;  
import flash.ui.MultitouchInputMode;

```
[SWF(width=320, height=460, frameRate=24, backgroundColor=0xEB7F00)]
public class TouchExample2 extends Sprite
{
    private var dots:Object;
    private var labels:Object;
    private var labelFormat:TextFormat;
    private var dotCount:uint;
    private var dotsLeft:TextField;
    private static const LABEL_SPACING:uint = 15;
    
    public function TouchExample2()
    {
        super();

        this.labelFormat = new TextFormat();
        labelFormat.color = 0xACF0F2;
        labelFormat.font = "Helvetica";
        labelFormat.size = 11;
        
        this.dotCount = 0;

        this.dotsLeft = new TextField();
        this.dotsLeft.width = 300;
        this.dotsLeft.defaultTextFormat = this.labelFormat;
        this.dotsLeft.x = 3;
        this.dotsLeft.y = 0;
        this.stage.addChild(this.dotsLeft);
        this.updateDotsLeft();

        this.dots = new Object();
        this.labels = new Object();

        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
        this.stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
        this.stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
        this.stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
    }

    private function onTouchBegin(e:TouchEvent):void
    {
        if (this.dotCount == Multitouch.maxTouchPoints) return;
        var dot:Sprite = this.getCircle();
        dot.x = e.stageX;
        dot.y = e.stageY;
        this.stage.addChild(dot);
        dot.startTouchDrag(e.touchPointID, true);
        this.dots[e.touchPointID] = dot;
        
        ++this.dotCount;

        var label:TextField = this.getLabel(e.stageX + ", " + e.stageY);
        label.x = 3;
        label.y = this.dotCount * LABEL_SPACING;
        this.stage.addChild(label);
        this.labels[e.touchPointID] = label;

        this.updateDotsLeft();
    }
    
    private function onTouchMove(e:TouchEvent):void
    {
        var label:TextField = this.labels[e.touchPointID];
        label.text = (e.stageX + ", " + e.stageY);
    }
    
    private function onTouchEnd(e:TouchEvent):void
    {
        var dot:Sprite = this.dots[e.touchPointID];
        var label:TextField = this.labels[e.touchPointID];
        
        this.stage.removeChild(dot);
        this.stage.removeChild(label);
        
        delete this.dots[e.touchPointID];
        delete this.labels[e.touchPointID];
        
        --this.dotCount;

        this.updateDotsLeft();
    }
    
    private function getCircle(circumference:uint = 40):Sprite
    {
        var circle:Sprite = new Sprite();
        circle.graphics.beginFill(0x1695A3);
        circle.graphics.drawCircle(0, 0, circumference);
        return circle;
    }

    private function getLabel(initialText:String):TextField
    {
        var label:TextField = new TextField();
        label.defaultTextFormat = this.labelFormat;
        label.selectable = false;
        label.antiAliasType = AntiAliasType.ADVANCED;
        label.text = initialText;
        return label;
    }
    
    private function updateDotsLeft():void
    {
        this.dotsLeft.text = "Touches Remaining: " + (Multitouch.maxTouchPoints - this.dotCount);
    }
}

```

}

The above code is working. (But only listening for a TouchEvent once).

Can anyone shed light on my problem?  
Many thanks in advance. :thumb:
