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 2013-2-2

@author Javid Jafari
Get Adobe Flash player
by J.J 02 Feb 2013
/**
 * Copyright J.J ( http://wonderfl.net/user/J.J )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2fNf
 */

package {

    import flash.events.MouseEvent;

    import flash.display.MovieClip;

    import flash.filters.BevelFilter;

    import flash.events.Event;

    import flash.display.Sprite;

    /**

     * @author Javid Jafari

     */

     [SWF(backgroundColor="#000000", frameRate="30", width="200", height="200")]

    public class simplegame extends Sprite {

        private static var COLORS : Array;

        private static var BOXESS : Vector.<MovieClip>;

        private var bevelFilter : BevelFilter;

        public function simplegame() {

            if(stage) inits()

            else addEventListener(Event.ADDED_TO_STAGE, inits)

        }



        private function inits(event : Event=null) : void {

            stage.scaleMode='exactFit'

            BOXESS=new Vector.<MovieClip>()

            COLORS=[0xff0000,0x00ff00,0x0000ff,0x112233]

            bevelFilter=new BevelFilter(2,45,0x000000)

            var c:uint

            for (var i : int = 0; i <=10; i++) {

                for (var j : int = 0; j < 10; j++) {

                    c=Math.floor(Math.random()*COLORS.length)

                    BOXESS.push(createBox(j*20,i*20,COLORS[c]))

                    

                }

            }

            stage.addEventListener(MouseEvent.MOUSE_DOWN, stageDown)

        }



        private function stageDown(event : MouseEvent) : void {

            

            var clip:MovieClip=event.target as MovieClip

            if(!clip) return;

            checkClips(clip)

            checkForFill()

    

        }

        private function checkForFill() : void {

            

            for(var i:String in BOXESS){

            

                if(BOXESS[i] && !BOXESS[i].parent && Number(i)-10>=0 && BOXESS[Number(i)-10]){

                 BOXESS[Number(i)-10].y+=20

                 BOXESS[i]=BOXESS[Number(i)-10]

                 BOXESS[Number(i)-10]=null

                 checkForFill()

                }else if(!BOXESS[i] && Number(i)-10>=0 &&  BOXESS[Number(i)-10]){

                 BOXESS[Number(i)-10].y+=20

                 BOXESS[i]=BOXESS[Number(i)-10]

                 BOXESS[Number(i)-10]=null

                 checkForFill()

                }

            }

            

        }







        private function checkClips(_clip:MovieClip) : void {

            var center:int=BOXESS.indexOf(_clip)

            var currentColor:uint=_clip.color

            var pos:Object={

            center:center,

            buttom:center+10,

            top:center-10,

            right:center+1,

            left:center-1

            }

            

    //    if(checkIndex(pos.center))    remove(BOXESS[pos.center],currentColor,pos.center)

        if(checkIndex(pos.buttom))    remove(BOXESS[pos.buttom],currentColor,pos.buttom)

        if(checkIndex(pos.top))    remove(BOXESS[pos.top],currentColor,pos.top)

        if(pos.right%10!=0 && checkIndex(pos.right))    remove(BOXESS[pos.right],currentColor,pos.right)

        if(pos.center%10!=0 && checkIndex(pos.left))    remove(BOXESS[pos.left],currentColor,pos.left)    

        }



        private function checkIndex(index:Number) : Boolean {

            return index>-1 && index<100

        }



        private function remove(disp:MovieClip,ck:uint,index:int) : void {

            if( disp && disp.parent && disp.color==ck){

                var inx:int=BOXESS.indexOf(disp);removeChild(disp),checkClips(disp)

                }

        }



        private function createBox(_x:Number,_y:Number,color:uint) : Sprite {

            var box:MovieClip=new MovieClip()

            box.x=_x,box.y=_y

            box.graphics.beginFill(color)

            box.graphics.drawRoundRect(0, 0, 20, 20, 5)

            box.graphics.endFill()

            box.filters=[bevelFilter]

            box.color=color

            addChild(box)

            return box

        }

    }

}