flash on 2015-7-12

by mutantleg
♥0 | Line 53 | Modified 2015-07-12 02:46:27 | MIT License
play

ActionScript3 source code

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

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
           
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);            
            stage.addEventListener(MouseEvent.MOUSE_UP, onMup);
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public function onMdown(e:MouseEvent):void { mbutton = 1; }
        public function onMup(e:MouseEvent):void { mbutton = 0; mclick = kt+1; }
        public function isClick():Boolean {  return mclick == kt; }
        
        public var mbutton:int = 0;
        public var mx:Number = 0;
        public var my:Number = 0;
        public var kt:int = 0;
        public var mclick:int = 0;
        
        public var cx:Number = 230;
        public var cy:Number = 230;
        
        
        
        public function onEnter(e:Event):void
        {
            kt += 1;            
            mx = stage.mouseX;    my = stage.mouseY;
            resetButton();
            
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            graphics.drawRect(8,8,465-16,465-16);
            
            midButton(10, 230, 48, 64, 32);
            midButton(20, 230, 416, 64, 32);
            midButton(30, 48, 230, 32, 64);
            midButton(40, 416, 230, 32, 64);
            
            if (btnPush == 10) { cy -=32; }
            if (btnPush == 20) { cy +=32; }
            if (btnPush == 30) { cx -=32; }
            if (btnPush == 40) { cx +=32; }
            
            graphics.drawCircle(cx,cy, 16);

            
        }//onenter
        
        public var btnPush:int = -1;
        public var btnOver:int = -1;
        
        public function resetButton():void { btnPush = -1; btnOver = -1; }

        public function midButton(id:int, ax:Number, ay:Number, xr:Number, yr:Number):void
        { drawButton(id, ax-xr,ay-yr, xr+xr,yr+yr);   }
        
        
        public function drawButton(id:int, ax:Number,ay:Number, aw:Number, ah:Number):void
        {  var over:Boolean;    over = (mx < ax || my < ay || mx > ax + aw || my > ay + ah) == false;  
           if (mbutton == 0 && over) { btnOver = id; }
           if (mbutton == 1 && over) { ax+=1; ay+=1; }
           if (isClick() && over) { btnPush = id;  }  
           graphics.lineStyle(over?2:1, 0);   graphics.beginFill(0xA0A0A0, 0.8);
           graphics.drawRect(ax, ay, aw, ah); graphics.endFill(); 
        }//drawbutton
        
        
    }//classend
}