In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2015-7-10

Get Adobe Flash player
by mutantleg 10 Jul 2015
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/89xO
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            
            vecRect = new Vector.<xRect>(0, false);
            
            var a:xRect;
            a = new xRect();          a.cw = 64; a.ch =64;              vecRect.push(a);
            a.cx=230; a.cy = 230;
            a = new xRect();          a.cw = 64; a.ch =64;              vecRect.push(a);
            a.cx=230; a.cy = 330;
            a = new xRect();          a.cw = 124; a.ch =64;              vecRect.push(a);
            a.cx=230; a.cy = 130;
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMup);            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var vecRect:Vector.<xRect>;
        
        public var curOver:xRect = null;
        public var curSel:xRect = null;

        public var mbutton:int = 0;

        public function onMdown(e:MouseEvent):void
        {
            mbutton = 1;
                       
        }//onmdown
        
        public function onMup(e:MouseEvent):void
        {
            mbutton = 0;
        }//onmup
       
       
        public var dragMode:int = 0; 
        public var dragx:Number = 0;
        public var dragy:Number = 0;
        public var cw:Number = 8;
        public var ch:Number = 8;
        
        public function onEnter(e:Event):void
        {
            var mx:Number; var my:Number;            
            mx = stage.mouseX; my = stage.mouseY;

            var ax:Number; var ay:Number;
            var aw:Number; var ah:Number;
            
            graphics.clear();
            graphics.lineStyle(2, 0);

                    if (mbutton == 0)
                    if (dragMode > 0)
                    { dragMode = 0; }

                    
                    if (dragMode == 1)
                    {
                      a = curSel;
                       a.cx = mx+dragx;   a.cy = my+dragy;
                       a.cx = Math.floor(a.cx/cw)*cw;
                       a.cy = Math.floor(a.cy/ch)*ch;                            
                    }//endif

                    if (dragMode == 2)
                    {
                      a = curSel;
                       a.cw = mx-a.cx;
                       a.ch = my-a.cy;
                       a.cw = Math.floor(a.cw/cw)*cw;
                       a.ch = Math.floor(a.ch/ch)*ch;                                
                       if (a.cw < 16) {a.cw=16;}
                       if (a.ch < 16) {a.ch=16;}   
                    }//endif
            
            
            
            curOver = null;
            var i:int; var num:int; var a:xRect;
            num = vecRect.length;
            for (i =0; i<num;i++)
            {
              a = vecRect[i];   
              if ( (mx < a.cx || my < a.cy || mx > a.cx + a.cw || my > a.cy + a.ch) == false) { curOver = a; }
              graphics.beginFill(0xff, 0.2);
               graphics.drawRect(a.cx, a.cy, a.cw, a.ch);  
              graphics.endFill();  
                
            }//nexti


          
                a = curSel;
                if (a != null)
                if (dragMode != 1)
                {
                    ax = a.cx+a.cw-8;
                    ay = a.cy+a.ch-8;
                    aw=16; ah=16;
                    graphics.drawRect(ax, ay, aw, ah);
                    if ((mx < ax || my < ay || mx > ax + aw || my > ay + ah) == false)
                    if (mbutton > 0)
                    if (dragMode == 0)
                    {
                      dragMode = 2;
                      dragx = curOver.cx-mx;
                      dragy = curOver.cy-my;
                    }//endif2
                }//endif

                if (mbutton > 0)
                if (dragMode == 0)
                if (curOver != null)
                {
                   dragMode = 1;
                   dragx = curOver.cx-mx;
                   dragy = curOver.cy-my;
                   curSel = curOver;
                }//endif
            
        }//onenter
        
    }//classend
}

internal class xRect
{
   public var cx:Number = 0;
   public var cy:Number = 0;
   public var cw:Number = 16;
   public var ch:Number = 16;
    
}//xrect