Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import caurina.transitions.Tweener;
- import flash.display.Sprite;
- import flash.events.TouchEvent;
- import flash.events.Event;
- import flash.ui.Multitouch;
- import flash.ui.MultitouchInputMode;
- [SWF(width="1024", height="600", backgroundColor="#cccccc")]
- public class MultiTouch extends Sprite
- {
- public var dots:Object = {};
- public function MultiTouch()
- {
- trace('starting MultiTouch')
- addEventListener(Event.ADDED_TO_STAGE, onAdded);
- }
- private function onAdded(event:Event):void
- {
- Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
- stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
- stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
- }
- public const RADIUS:int = 50;
- public const CROSS:int = 75;
- private function onTouchBegin(e:TouchEvent):void
- {
- var tpid:int = e.touchPointID;
- var dot:Sprite = new Sprite();
- dot.graphics.beginFill(int(Math.random() * 0xffffff));
- dot.graphics.drawCircle(0, 0, RADIUS);
- dot.graphics.endFill();
- dot.graphics.lineStyle(0);
- dot.graphics.moveTo(-CROSS, 0);
- dot.graphics.lineTo(CROSS, 0);
- dot.graphics.moveTo(0, -CROSS);
- dot.graphics.lineTo(0, CROSS);
- this.addChild(dot);
- trace('touch', tpid);
- dot.x = e.stageX;
- dot.y = e.stageY;
- dot.startTouchDrag(tpid, true);
- dots[tpid] = dot;
- }
- private function onTouchEnd(e:TouchEvent):void
- {
- var tpid:int = e.touchPointID;
- var dot:Sprite = dots[tpid];
- dot.stopTouchDrag(tpid);
- delete dots[tpid];
- Tweener.addTween(dot, {alpha: 0, time: 1, transition: 'linear',
- onComplete: this.removeChild,
- onCompleteParams: [dot]
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment