본문 바로가기

AS3/아이폰

FB4.5: ActionScript Mobile Project - iOS - Multitouch with TouchPoints

Flash Builder 4.5 ActionScript Mobile Project의 동영상 자료

플래시빌더 4.5 에서 Actionscript Mobile Project를 이용해 아이폰에서 터치이벤트를 활용한 예제
package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.TouchEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.ui.Multitouch;
	import flash.ui.MultitouchInputMode;
	
	[SWF (backgroundColor="#cccccc", frameRate="60" ) ]
	public class MultiTouchTest extends Sprite
	{
		private var spots:Array;

		private var tf:TextField;
		public function MultiTouchTest()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			setTextField();
			
			if ( Multitouch.supportsTouchEvents )
			{
				init();
			}else
			{
				tf.text = "no support multitouch";
			}
		}
		
		private function setTextField():void
		{
			
			tf = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = "hello";
			tf.multiline = true;
			addChild ( tf );
			
			var textFormat:TextFormat = new TextFormat(null, 20 );
			tf.setTextFormat( textFormat );
		}
		
		private function init():void
		{
			Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
			
			stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchEventHandler );
			stage.addEventListener(TouchEvent.TOUCH_END, touchEventHandler );
			
			spots = [];
		}
		
		protected function touchEventHandler(event:TouchEvent):void
		{
			var spot:Sprite;
			tf.appendText( event.type + "\n" );
			tf.appendText( event.touchPointID.toString() + "\n" );
			
			
			if ( event.type == "touchBegin" )
			{
				spot = getCircle();
				spot.x = event.stageX;
				spot.y = event.stageY;
				spot.startTouchDrag( event.touchPointID, true );
				this.stage.addChild( spot );
				
				spots[event.touchPointID] = spot;
			} else {
				
				spot = this.spots[event.touchPointID];
				this.stage.removeChild(spot);
				
				delete this.spots[event.touchPointID];
			}
			
		}
		
		private function getCircle( circ:uint = 60 ):Sprite
		{
			var sprite:Sprite = new Sprite();
			sprite.graphics.beginFill( Math.random() * 0xffffff);
			sprite.graphics.drawCircle( 0, 0, circ );
			
			
			return sprite;
		}
	}
}


Multitouch with TouchPoints 


플래시 빌더 4.5 모바일 프로젝트에 관련해서 도움을 얻을 수 있는 사이트
http://www.tutorialsbyibrent.com/

해당 사이트에 있는 소스들