flash on 2016-10-31

by mutantleg
♥0 | Line 118 | Modified 2016-10-31 07:53:16 | 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/u4KM
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {

            vecThing = new Vector.<xThing>(0, false);

            var a:xThing;
            a = new xThing();
            vecThing.push(a);

            a = new xThing();
            a.tx=3;a.ty=3;
            a.tw=2;a.th=2;
            vecThing.push(a);

            a = new xThing();
            a.tx=8; a.ty=3;
            a.tw=1;a.th=3;
            vecThing.push(a);

            a = new xThing();
            a.tx=10; a.ty=3;
            a.tw=3;a.th=5;
            vecThing.push(a);

 
          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; }
        
        public var mbutton:int = 0;
        public var mhold:int = 0;
 
        public var holdThing:xThing = null;
        
        public var vecThing:Vector.<xThing>;
        
        public function onEnter(e:Event):void
        {
          graphics.clear();
          graphics.lineStyle(2, 0);
          
          
          var gx:Number; var gy:Number;
          var gw:Number; var gh:Number;
          gx=32;gy=32;
          gw=384; gh=256;
          
          graphics.drawRect(gx,gy,gw,gh);
          
          
          var mx:Number; var my:Number;
          mx = stage.mouseX; my = stage.mouseY;
          
          if (mbutton >0){mhold+=1;} 
          else {mhold=0;} 

          var hx:Number; var hy:Number;
          var hw:Number; var hh:Number;
          if (holdThing != null)
          {
           a = holdThing;     

              hx=Math.floor(mx/32)*32; hy=Math.floor(my/32)*32;
              hw=a.tw*32; hh=a.th*32;
              
           graphics.beginFill(a.c, 1);
           graphics.drawRect(hx,hy,hw,hh);   
           graphics.endFill();   
           
           var numOver:int;
           var lastOver:xThing;
           lastOver = null;
           numOver = 0;
         //  var over:Boolean;
          // over = false;
            
               num = vecThing.length;
              for (i=0;i< num;i+=1 )
              {
               a = vecThing[i];
               if (a==holdThing){continue;}
               ax = a.tx *32; ay = a.ty*32;
               aw = a.tw*32; ah = a.th*32;
               if ( ((ax+aw<=hx)||(ay+ah<=hy)||(hx+hw<=ax)||(hy+hh<=ay)) ){continue;}
             //  over = true; break;     
               numOver += 1;
               lastOver = a;
              }//nexti
         
              if ( hx<gx || hy <gy || hx+hw>gx+gw || hy+hh>gy+gh) { numOver=99; }
              
              
              if (numOver <2 && mhold == 1)
              {
                  mhold=2;
               a = holdThing;
               a.tx = hx/32;
               a.ty =hy/32;
               holdThing=null;    
               if (numOver == 1)
               {
                holdThing = lastOver;   
                }
              }//endif2
             
          }//endif
            
          var ax:Number; var ay:Number;
          var aw:Number; var ah:Number;
          var a:xThing;
          var i:int;
          var num:int;
          num = vecThing.length;
          for (i=0;i< num;i+=1 )
          {
           a = vecThing[i];
           if (a==holdThing){continue;}
           ax = a.tx *32; ay = a.ty*32;
           aw = a.tw*32; ah = a.th*32;
           graphics.beginFill(a.c, 0.5);
           graphics.drawRect(ax,ay,aw,ah);   
           graphics.endFill();   
           if (mx<ax||my<ay||mx>ax+aw||my>ay+ah){ continue; }
           graphics.drawCircle(ax+aw*0.5, ay+ah*0.5, 4);
            if (mhold ==1)
            { //a.c = Math.random()*0xFFffFF;
                mhold=2;
              if (holdThing == null) { holdThing = a; } 
            }
          }//nexti 
            
            
        }//onenter        
        
    }//classend 
}

internal class xThing
{
  public var tx:int = 0;
  public var ty:int = 0;   
  public var tw:int = 1;
  public var th:int = 1;  
  public var c:uint = Math.random()*0xFFffFF;
}//xthing