childrenの重なり順を変える
♥0 |
Line 55 |
Modified 2014-06-26 14:29:50 |
MIT License
archived:2017-03-20 03:18:51
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zHrn
*/
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class FlashTest extends Sprite {
private var tf:TextField = new TextField();
public function FlashTest() {
// write as3 code here..
this.graphics.beginFill(0xffffff);
this.graphics.drawRect(0,0,455,455);
this.graphics.endFill();
stage.addEventListener(MouseEvent.MOUSE_DOWN,add);
addChild(tf);
tf.text = "test";
}
private function add(e:MouseEvent):void{
if(_sw)return;
tf.text = mouseX.toString();
var s:Sprite = new Sprite();
stage.addChild(s);
s.addEventListener(MouseEvent.MOUSE_OVER,onOver);
s.addEventListener(MouseEvent.MOUSE_OUT,rollOut);
s.addEventListener(MouseEvent.MOUSE_DOWN,onDrag);
s.addEventListener(MouseEvent.MOUSE_UP,onDrop);
s.x = this.mouseX;
s.y = this.mouseY;
s.graphics.lineStyle(1,0);
s.graphics.beginFill(Math.random()*0xffffff);
s.graphics.drawCircle(0,0,30);
s.graphics.endFill();
var s2:Sprite = new Sprite();
s.addChild(s2);
s2.graphics.beginFill(0x0);
s2.graphics.drawCircle(0,0,10);
s2.graphics.endFill();
_sw=true;
}
private var _sw:Boolean;
private function onOver(e:MouseEvent):void{
_sw=true;
tf.text = e.currentTarget.name;
}
private function rollOut(e:MouseEvent):void{
_sw=false;
}
private function onDrag(e:MouseEvent):void{
e.currentTarget.startDrag();
tf.text = e.currentTarget.parent.getChildIndex(e.currentTarget);
//this.startDrag();
e.currentTarget.parent.setChildIndex(e.currentTarget,e.currentTarget.parent.numChildren-1); //並べ替え
//var s:DisplayObject = stage.getChildByName(e.currentTarget.name);//ディスプレイオブジェクト取得
//stage.setChildIndex(s,stage.numChildren-1); //並べ替え
tf.appendText(" -> "+e.currentTarget.parent.getChildIndex(e.currentTarget));
}
private function onDrop(e:MouseEvent):void{
e.currentTarget.stopDrag();
}
}
}