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 2014-10-8

Get Adobe Flash player
by mutantleg 08 Oct 2014

    Talk

    greentec at 10 Oct 2014 08:15
    oh, you made your own UI. good.
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/R1FD
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
           myGui = new xTestGui();
           addChild(myGui);
            
           stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
           stage.addEventListener(MouseEvent.MOUSE_UP, onMup); 
           stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var mdown:int = 0;
        public function onMdown(e:MouseEvent):void { mdown = 1;}
        public function onMup(e:MouseEvent):void { mdown = 0;}            
        
        public var myGui:xTestGui;
                    
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2,0);
            
            myGui.mdown = mdown;
            myGui.update();
            
        }//onenter
        
    }//classend
}
import flash.display.Sprite;

internal class xMiniGui extends Sprite
{
    public var mx:Number = 0;
    public var my:Number = 0;
    public var mdown:int = 0;
    public var overid:int = 0; //mouseover
    public var curid:int = 0; //infocuse
    
    public var press:int = 0;
    
    public function xMiniGui()
    {
        this.buttonMode= true;
    }//ctor
    
    //update and draw actually
    public function update():void
    {
       mx = this.mouseX;
       my = this.mouseY;
       
       graphics.clear();
       graphics.lineStyle(2,0);
       
       overid = 0;
       press = 0;
       
        doGui();

       if (overid != 0 || curid != 0) { this.useHandCursor = true; }
       else { this.useHandCursor = false; }
       
       if (mdown == 0) { curid  = 0; }
       
       
    }//update
    
    public function doGui():void
    {
    }//dogui
    
    public function isMouseOver(ax:Number,ay:Number,aw:Number,ah:Number):Boolean
    {
      if (mx < ax) { return false; }  
      if (my < ay) { return false; }
      if (mx > ax+aw) { return false; }
      if (my > ay+ah){ return false; }
      return true;
    }//isover
    
    public function doButton(id:int, ax:Number,ay:Number,aw:Number,ah:Number):int
    {
        if (isMouseOver(ax,ay,aw,ah))
        {
          overid = id; if (curid == 0 && mdown > 0)   { curid = id; }
        }//endif
        
        graphics.lineStyle();
        graphics.beginFill(0, 0.5);
         graphics.drawRect(ax+4,ay+4,aw,ah);
        graphics.endFill();

        graphics.lineStyle(2,0);    
        graphics.beginFill(overid==id ? 0x808080 : 0x404040,  1);
         graphics.drawRect(ax+(curid==id?2:0),ay+(curid==id?2:0),aw,ah);
        graphics.endFill();
    
        if (mdown == 0 && curid == id && overid == id) { press = id; return 1; }
        
        return 0;
    }//dobutton
    
}//minigui


internal class xTestGui extends xMiniGui
{
    
    public var state:int = 0;
  
    override  public function doGui():void
    {
       var i:int;

        graphics.drawRect(0,0,320,240);
        graphics.drawRect(0,64,320,2);
        
        doButton(10, 16,16, 64, 32);
        doButton(20, 16+100,16, 64, 32);
        doButton(30, 16+200,16, 64, 32);
        
        if (press == 10) { state = 0;}
        else if (press == 20) { state = 1;}
        else if (press == 30) { state = 2;}
        
        if (state == 0)
        {
            doButton(110, 16,96, 128, 32);
            doButton(120, 16,96+40, 128, 32);
            doButton(130, 16,96+80, 128, 32);
        }//endif   
        
        if (state == 1)
        {
           for (i = 0; i < 9; i++)
           {
              doButton(200+(i*10), 96+int(i%3)*40,96+int(i/3)*40, 32, 32);               
           }//nexti
            
        }//endif
        
        if (state == 2)
        {
           for (i = 0; i < 9; i++)
           {
              doButton(300+(i*10), 16+i*24,96, 24, 32);               
           }//nexti
            
        }//endif

        
        
        
    }//dogui

}//testgui