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 2009-8-30

Get Adobe Flash player
by hacker_wuokoi5f 30 Aug 2009
    Embed
/**
 * Copyright hacker_wuokoi5f ( http://wonderfl.net/user/hacker_wuokoi5f )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7eE9
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.filters.GlowFilter;
    
    public class FlashTest extends Sprite {
        
        public static const SIZE:Number = 30;
        public static const INCREASE:Number = 15;
        protected var hash:Object;
        protected var grid:Sprite;
        protected var t:TextField;
        protected var glow:GlowFilter;
        
        public function FlashTest() {                    
            t = new TextField();            
            addChild(t);
            t.width = stage.stageWidth;
            t.height = stage.stageHeight;
            t.text = 'hello world';            
            
            hash = {};
            
            glow = new GlowFilter();
            
            buildGrid();                        
        }
        
        protected function buildGrid():void {
            grid = new Sprite();
            addChild(grid);           
            
            //rows
            for (var i:int=0; i < 8; i++) {
                      
                //cols
                for (var j:int=0; j < 8; j++) {
                    //draw the thumb
                    var b:Sprite = new Sprite();
                    b.graphics.beginFill(0x0);
                    b.graphics.drawRect(-SIZE >> 1, -SIZE >> 1, SIZE, SIZE);
                    b.graphics.endFill();                
                
                    grid.addChild(b);
                    b.x = j * (SIZE+2);
                    b.y = i * (SIZE+2);
                    
                    b.addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver, false, 0, true);
                    b.addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut, false, 0, true);
                    
                    hash[i+','+j] = b;
                    b.name = i+','+j;
                    
                }
            }
            
            grid.x = stage.stageWidth - grid.width >> 1;
            grid.y = stage.stageHeight - grid.height >> 1;
        }
        
        protected function handleMouseOver(event:MouseEvent):void {
            var b:Sprite = event.target as Sprite;
           
            b.width = b.height = SIZE + INCREASE;                        
            //b.x -= INCREASE/2;
            //b.y -= INCREASE/2;
            b.filters = [glow];
            grid.addChild(b); //bring to top of display list              
                                    
            var row:int = int(b.name.split(',')[0]);
            var col:int = int(b.name.split(',')[1]); 
            for (var i:int = -1; i < 2; i ++) {
                for (var j:int = -1; j < 2; j++) {                            
                    var rc:String = int(row + i) + ',' + int(col + j);
                    if (hash[rc] != undefined) {
                        
                        if (i == 0 && j == 0) { continue; } //skip the center piece
                        
                        if (i == -1) { hash[rc].rotationX = -45; }
                        if (i == 1) { hash[rc].rotationX = 45; }
                        
                        if (j == -1) { hash[rc].rotationY = 45; }
                        if (j == 1) { hash[rc].rotationY = -45; }
                        
                    }
                }      
            }           
        }
        
        protected function handleMouseOut(event:MouseEvent):void {
            var b:Sprite = event.target as Sprite;
            
            b.width = b.height = SIZE;            
           // b.x += INCREASE/2;
           // b.y += INCREASE/2;
            b.filters = [];

            var row:int = int(b.name.split(',')[0]);
            var col:int = int(b.name.split(',')[1]); 
            for (var i:int = -1; i < 2; i ++) {
                for (var j:int = -1; j < 2; j++) {                            
                    var rc:String = int(row + i) + ',' + int(col + j);
                    if (hash[rc] != undefined) {
                            
                        if (i == 0 && j == 0) { continue; } //skip the center piece

                        hash[rc].rotationX = 0;                     
                        hash[rc].rotationY = 0; 
                        
                    }
                }      
            }
        }
    }
}