Hatena::Groupactionscript

ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記

2009年08月07日 金曜日

Phase01(ActionScript 3.0による数学・物理学表現[入門編]から)

| 12:11 | Phase01(ActionScript 3.0による数学・物理学表現[入門編]から) - ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記 を含むブックマーク はてなブックマーク - Phase01(ActionScript 3.0による数学・物理学表現[入門編]から) - ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記 Phase01(ActionScript 3.0による数学・物理学表現[入門編]から) - ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記 のブックマークコメント

phase01.xml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:comp="*" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<comp:Phase01>
	</comp:Phase01>
</mx:Application>

Phase01.as

package
{
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	import models.Circle;
	import mx.core.UIComponent;

	public class Phase01 extends UIComponent{
		public var obj:Array;
		public var timer:Timer;
		public var rollovered:Boolean;

		public function Phase01():void{
			obj = new Array();
			for(var i:Number=0; i<10; i++){
				obj.push(new Circle());
			}

			for(var j:Number=0; j<obj.length; j++){
				obj[j].create();
				obj[j].x = 100;
				obj[j].y = 100;
				//obj[j].addEventListener(MouseEvent.MOUSE_OVER, onOver);
				//obj[j].addEventListener(MouseEvent.MOUSE_OUT, onOverOut);
				addChild(obj[j]);
			}

			var s:Circle = new Circle();
			s.create();
			s.x = 100;
			s.y = 100;
			s.addEventListener(MouseEvent.MOUSE_OVER, onOver);
			s.addEventListener(MouseEvent.MOUSE_OUT, onOverOut);
			addChild(s);

			timer = new Timer(33);
			timer.addEventListener(TimerEvent.TIMER, loop);
			timer.start();
		}

		public function onOver(event:MouseEvent):void{
			rollovered = true;
		}

		public function onOverOut(event:MouseEvent):void{
			rollovered = false;
		}

		public function loop(event:TimerEvent):void{
			for(var i:Number=0;i<obj.length;i++){
				var koko:Point = new Point();
				if(rollovered){
					if(i == 0){
						koko.x = 100 + 80;
						koko.y = 100;
					}else{
						koko.x = obj[i-1].x + 80;
						koko.y = obj[i-1].y;
					}
				}else{
					if(i == 0){
						koko.x = this.stage.stageWidth + 140;
						koko.y = this.stage.stageHeight/2  -140;
					}else{
						koko.x = obj[i-1].x;
						koko.y = obj[i-1].y;
					}
				}
				
				obj[i].x += (koko.x - obj[i].x)/8;
				obj[i].y += (koko.y - obj[i].y)/8;
			}
		}
	}
}

models/Circle.as

package models
{
	import flash.display.Sprite;

	public class Circle extends Sprite{
		public var s:Sprite = new Sprite();
		
		public function Circle():void {
		}

		public function create():void {
			s.graphics.lineStyle(1,0xff0000);
			s.graphics.beginFill(0xffffff);
			s.graphics.drawCircle(0, 0, 50);
			s.graphics.endFill();
			addChild(s);
		}

	}
}

AkoAko 2013/03/15 16:48 That's a cunning answer to a challeingng question

baksyfowxdmbaksyfowxdm 2013/03/18 21:14 yEYkaJ <a href="http://cfjmsbgzkzof.com/">cfjmsbgzkzof</a>

spgqntxtrspgqntxtr 2013/03/19 07:14 sT9F5e , [url=http://hkfdkmnqolzr.com/]hkfdkmnqolzr[/url], [link=http://tyhkflaefmtf.com/]tyhkflaefmtf[/link], http://cwwqkmocsjxu.com/

MarioMario 2015/09/30 15:05 YMMD with that anwrse! TX

LeticiaLeticia 2015/10/09 07:33 Always a good job right here. Keep rolling on <a href="http://yucqbuigpz.com">thghoru.</a>

KarimKarim 2015/10/09 11:57 Hi, Humming Bird. I just wanted to say thank you so much for tnkiag the time to tell others about what is going on and being a warrior for God. I am a Police Officer and I am able to drive around and patrol while listening.I know God will bless you for all your hard work. Thanks so much ! God Bless, Malinda http://llayxsfoac.com [url=http://njnzim.com]njnzim[/url] [link=http://wjqsxjvovzz.com]wjqsxjvovzz[/link]

MandeMande 2015/10/10 06:39 AFAIC <a href="http://xnfvqib.com">th'ats</a> the best answer so far!

AfricaAfrica 2015/10/12 07:10 Hi hummingbird its trobe65 i watend to know how i can send you some news articles and some pictures of the new muslim tempel being built beside us.. love you and all the news, and biblical insight that you do. I learn alot from it.Trobe65 http://iomkcvzd.com [url=http://oxpgfldmp.com]oxpgfldmp[/url] [link=http://kqnwdncbns.com]kqnwdncbns[/link]

ゲスト



トラックバック - http://actionscript.g.hatena.ne.jp/d4-1977/20090807