flash on 2009-7-21

by pykgg476
♥0 | Line 40 | Modified 2009-07-21 15:37:32 | MIT License
play

ActionScript3 source code

/**
 * Copyright pykgg476 ( http://wonderfl.net/user/pykgg476 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/prVG
 */

package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class sample extends Sprite
	{
		private var parent1:Sprite;
		private var parent2:Sprite;
		private var ball:Sprite;
		
		public function sample()
		{
			init();
		}
		
		private function init():void{
			parent1 = new Sprite();
			addChild(parent1);
			parent1.graphics.lineStyle(1,0);
			parent1.graphics.drawRect(-50,-50,100,100);
			parent1.x=60;
			parent1.y=60;
			
			parent2 = new Sprite();
			addChild(parent2);
			parent2.graphics.lineStyle(1,0);
			parent2.graphics.drawRect(-50,-50,100,100);
			parent2.x=170;
			parent2.y=60;
			
			ball = new Sprite();
			parent1.addChild(ball);
			ball.graphics.beginFill(0xff0000);
			ball.graphics.drawCircle(0, 0, 40);
			ball.graphics.endFill();
			ball.addEventListener(MouseEvent.CLICK,onBallClick);
					
		}
		
		private function onBallClick(event:MouseEvent):void{
			if(parent1.numChildren == 1){
				
				parent2.addChild(ball);
			
			}else if(parent2.numChildren == 1){
				parent1.addChild(ball);
			}
			
		}
		
		
	}