flash on 2012-3-2

by tepe
♥0 | Line 37 | Modified 2012-03-02 14:23:45 | MIT License
play

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/8zL7
 */

package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    public class FlashTest extends Sprite {
        private var tf:TextField = new TextField();
        public function FlashTest() {
            // write as3 code here..
            
            //スプライト生成
            for(var i:int=0;i<10;i++){
                var s:Sprite = new Sprite();
                s.graphics.lineStyle(1,0x000000);
                s.graphics.beginFill(Math.random()*0xFFFFFF);
                s.graphics.drawCircle(150,150,50);
                s.graphics.endFill();
                s.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
                s.addEventListener(MouseEvent.MOUSE_UP,onUp);
                
                addChild(s);
            }
            tf.text = "test";
            tf.height =40;
            tf.width = 50;
            addChild(tf);
            tf.text = this.numChildren.toString();
            
            //addEventListener(MouseEvent.MOUSE_DOWN,onDown);
            //addEventListener(MouseEvent.MOUSE_DOWN,onUp);
            
        }
        
        private function onDown(e:MouseEvent):void{
            e.currentTarget.startDrag();
            //ドラッグした対象を最前面に持ってくる処理
            var _parent:DisplayObjectContainer = this.parent;//親を覚えておく
            this.parent.removeChild(this);
            _parent.addChild(this);
            tf.text = this.parent.getChildIndex(this).toString();
            e.stopPropagation();
        }
        
        private function onUp(e:MouseEvent):void{
            e.currentTarget.stopDrag();
            removeEventListener(MouseEvent.MOUSE_UP,onUp);
        }
    }
}