flash on 2013-7-6

by tepe
♥0 | Line 158 | Modified 2013-07-09 16:51:50 | 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/7Ak4
 */

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.text.*;
    import flash.ui.*;
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.CurveModifiers;
     
    public class FlashTest extends Sprite {
        private var s:Sprite = new Sprite();
        private var s2:Sprite = new Sprite();
        private var tf:TextField = new TextField();
        private var _drag:Boolean = false;
        private var _flag1:Boolean = false;
        public function FlashTest() {
            // write as3 code here..

            CurveModifiers.init();            
            addChild(tf);
            tf.x=300;
            addChild(s);
            s.graphics.lineStyle(1,0x000000);
            s.graphics.beginFill(0xff0000);
            s.graphics.drawCircle(0,0,20);
            s.graphics.endFill();
            
            addChild(s2);
            s2.graphics.lineStyle(0,0x000000);
            s2.graphics.beginFill(0xff0000,0);
            s2.graphics.drawRect(0,0,100,100);
            s2.graphics.endFill();
            s2.x = 100;
            s2.y = 200;
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN,onKey);
            
            
            addEventListener(MouseEvent.MOUSE_DOWN,onDrag);
            addEventListener(MouseEvent.MOUSE_UP,onDrop);
            //s2.addEventListener(MouseEvent.ROLL_OVER,onRoll);
            //s2.addEventListener(MouseEvent.ROLL_OUT,onOut);
            
        }
        private var idCnt:int=0;
        private function func1(col:uint=0xff0000):void{
            var sp:Sprite = new Sprite();
                        with(sp.graphics){
                            lineStyle(0,0x0);
                            beginFill(col)
                            drawCircle(0,0,20);
                            endFill();
                        }
                        sp.x = Math.random()*400;
                        sp.y = Math.random()*400;
                        stage.addChild(sp);
                        prev = objList[objList.length-1];
                        next = null;
                        objList.push(sp);
                        current = sp;
                        //sp["text"] = idCnt.toString();
            var str:String = new String();
            str = objList.length.toString();
            //str +="\n" + current["text"];
            //str +="\n" + prev["text"];
            tf.text = str;
            
            idCnt++;
            

        }

        private var current:Sprite;
        private var prev:Sprite;
        private var next:Sprite;
        private var objList:Array = new Array();
        
        private var _inputKey:Boolean;
        private var cBox:TextField;
        private function onKey(e:KeyboardEvent):void{
            
            if(_inputKey==false){
            if(e.keyCode == Keyboard.SPACE){
                cBox= new TextField();
                cBox.border = true;
                cBox.type="input";
                cBox.y = 400;
                cBox.height= 20;
                cBox.x = 100;
                stage.addChild(cBox);
                stage.focus = cBox;
                _inputKey=true;
                //draw2();
            }
            }//_inputKey==false
            else{
                if(e.keyCode == Keyboard.ENTER){
                    
                    if(cBox.text == " new"){
                        func1();
                    }
                    else if(cBox.text == " +")func1(0x0000ff);
                    else if(cBox.text == " =")func1(0x00ff00);

                    stage.focus = stage;
                    cBox.text = "";
                    stage.removeChild(cBox);
                    cBox=null;
                    _inputKey=false;
                }
                if(e.keyCode == Keyboard.SPACE){
                    if(cBox.text == " "){ 
                        stage.removeChild(cBox);
                        cBox=null;
                        _inputKey=false;
                    }

                }


            }


        }

        
        private function onOut(e:MouseEvent):void{
            s2.graphics.clear();
            s2.graphics.lineStyle(1,0x000000);
            s2.graphics.beginFill(0xff0000,0);
            s2.graphics.drawRect(0,0,100,100);
            s2.graphics.endFill();
        }

        private function onRoll(e:MouseEvent):void{
            if(_drag == true){
                s2.graphics.clear();
                s2.graphics.lineStyle(1,0x000000);
                s2.graphics.beginFill(0xff0000,0.1);
                s2.graphics.drawRect(0,0,400,100);
                s2.graphics.endFill();
            }

        }
        
        private function draw1():void{
            s2.graphics.clear();
            s2.graphics.lineStyle(1,0x000000);
            s2.graphics.beginFill(0xff0000,0.1);
            s2.graphics.drawRect(0,0,200,200);
            s2.graphics.endFill();
        }
        private function draw2():void{
            s2.graphics.clear();
            s2.graphics.lineStyle(0,0x000000);
            s2.graphics.beginFill(0xff0000,0);
            s2.graphics.drawRect(0,0,100,100);
            s2.graphics.endFill();
        }


        
        private function onFrame(e:Event):void{
            
            if(s2.x < stage.mouseX && stage.mouseX < s2.x+s2.width &&
               s2.y < stage.mouseY && stage.mouseY < s2.y+s2.height){
                _flag1=true;
            }
            else{
                _flag1=false;
            }
            if(_flag1==true){ 
                //draw1();
                Tweener.addTween(s2, { width:200, height:100, time:1} );
            }
            else{ 
                //draw2();
                Tweener.addTween(s2, { width:100, height:100, time:1} );
                
            }
            if(_drag==false){
                removeEventListener(Event.ENTER_FRAME,onFrame);
                Tweener.addTween(s2, { width:100, height:100, time:1} );
            }


        }


        private function onDrag(e:MouseEvent):void{
            removeChild(s);
            addChild(s);
            s.startDrag();
            addEventListener(Event.ENTER_FRAME,onFrame);
            _drag=true;
        }
        private function onDrop(e:MouseEvent):void{
            s.stopDrag(); 
            
            _drag=false;
        }



    }
}