静岡理工科大学 菅沼ホーム ActionScript 目次 索引

Point クラス

[内容]

  点の座標を保持します.

継承: Point → Object

[プロパティ]

[メソッド]

[使用例]

  1. Point クラスの使用例」と,そのプログラム( Point_e.as )です.小さな円が動き回ります.
    package
    {
    	import flash.display.Sprite;
    	import flash.display.Shape;
    	import flash.geom.Point;
    	import flash.events.Event;
    
    	[SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="30")]
    
    	public class Point_e extends Sprite
    	{
    		private var ball : Shape;
    		private var pt : Point;
    		private var a : Number;
    
    		public function Point_e()
    		{
    			init();
    		}
    		
    		private function init():void
    		{
    			a    = -Math.PI + Math.PI * Math.random();
    			pt   = new Point();
    			pt.x = 10 + Math.random() * (stage.stageWidth - 20);
    			pt.y = 10 + Math.random() * (stage.stageHeight - 20);
    			ball = new Shape();
    			ball.graphics.beginFill(0x00ff00);
    			ball.graphics.drawCircle(0, 0, 10);
    			ball.graphics.endFill();
    			ball.x = pt.x;
    			ball.y = pt.y;
    			addChild(ball);
    			addEventListener(Event.ENTER_FRAME, onEnterFrame);
    		}
    
    		private function onEnterFrame(event:Event):void
    		{
    			pt.offset(10 * Math.cos(a), 10 * Math.sin(a));
    			if (pt.x < 10) {
    				pt.x = 20 - pt.x;
    				if (a > 0)
    					a = Math.PI - a;
    				else
    					a = -(Math.PI + a);
    			}
    			if (pt.x > stage.stageWidth - 10) {
    				pt.x = 2 * stage.stageWidth - pt.x - 20;
    				if (a > 0)
    					a = Math.PI - a;
    				else
    					a = -(Math.PI + a);
    			}
    			if (pt.y < 10) {
    				pt.y = 20 - pt.y;
    				a = -a;
    			}
    			if (pt.y > stage.stageHeight - 10) {
    				pt.y = 2 * stage.stageHeight - pt.y - 20;
    				a = -a;
    			}
    			ball.x = pt.x;
    			ball.y = pt.y;
    		}
    	}
    }
    			

静岡理工科大学 菅沼ホーム ActionScript 目次 索引