flash on 2011-3-24
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/txZi
*/
package {
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
public class FlashTest extends Sprite {
private var s:Sprite;
private var s2:Sprite = new Sprite();
private var s3:Sprite = new Sprite();
private var buf:Array = new Array();
private var s4:Sprite = new Sprite();
public function FlashTest() {
// write as3 code here..
var txt1:TextField = new TextField();
stage.addChild(txt1);
txt1.text = "test";
txt1.x = 0;
txt1.y = 0;
txt1.text = "bbb";
s = new Sprite();
s.name = "s";
s2.name = "s2";
s3.name = "s3";
s2.scaleX = s2.scaleY = 0.3;
s3.scaleX = s3.scaleY = 0.5;
s.x =100; s.y = 100;
s2.x = 50; s2.y = 50; s2.rotation = 10;
s3.x = 20; s3.y = 20;
/*
s.graphics.beginFill(0x00ff00);
s.graphics.drawRect(0,0,100,100);
s.graphics.endFill();
*/
s2.graphics.beginFill(0xff0000);
s2.graphics.drawRect(-10,0,100,100);
s2.graphics.endFill();
s2.addEventListener(MouseEvent.ROLL_OVER,function(e:MouseEvent):void{
e.currentTarget.alpha = Math.random()*1.0;
});
stage.addChild(s4);
stage.addEventListener(MouseEvent.MOUSE_MOVE,function(e:MouseEvent):void{
s4.graphics.clear();
s4.graphics.beginFill(0x00ffff,0.8);
s4.graphics.drawCircle(0,0,10);
s4.graphics.endFill();
s4.x = e.stageX;
s4.y = e.stageY;
});
s3.graphics.beginFill(0x0000ff);
s3.graphics.drawRect(0,-60,100,100);
s3.graphics.endFill();
stage.addChild(s);
txt1.appendText("\ns2:"+s2.name);
s.addChild(s2);
s2.addChild(s3);
var obj:Object = new Object();
obj["aaa"] = s;
buf.push(obj);
obj = buf.pop();
addChild(obj.aaa);
//parentを外す
stage.addEventListener(MouseEvent.CLICK,remove);
/*
txt1.appendText("\ns3Parent:"+s3.parent.name);
s.addChild(s3);//親子関係に矛盾が出ないように切り替え順を考えること
s3.addChild(s2);
txt1.appendText("\n"+ s2.parent.name);
stage.addChild(s2);
txt1.appendText("\n"+s2.parent.name);
s.addChild(s2);
txt1.appendText("\n"+s2.parent.name);
*/
}
private function remove(e:MouseEvent):void{
s.addChild(s3);
s.removeChild(s2);
s.scaleX = s.scaleY *= s2.scaleX;
s.rotation += s2.rotation;
s.x += s2.x;
s.y += s2.y;
stage.removeEventListener(MouseEvent.CLICK,remove);
stage.addEventListener(MouseEvent.CLICK,add);
}
private function add(e:MouseEvent):void{
s.addChild(s2);
s2.addChild(s3);
s.scaleX = s.scaleY /= s2.scaleX;
s.rotation -= s2.rotation;
s.x -= s2.x; //parent のオフセット
s.y -= s2.y;
stage.addEventListener(MouseEvent.CLICK,remove);
stage.removeEventListener(MouseEvent.CLICK,add);
}
}
}