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

forked from: 自分を取ると1UPです!

迷走しすぎた。中身がグダグダなのでリファクタリング必須><
最初のほうが何故か必ずズレるのでその辺も修正する。
Get Adobe Flash player
by manaten 26 May 2010
/**
 * Copyright manaten ( http://wonderfl.net/user/manaten )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fPee
 */

// forked from kagetiyo523's 自分を取ると1UPです!
//迷走しすぎた。中身がグダグダなのでリファクタリング必須><
//最初のほうが何故か必ずズレるのでその辺も修正する。
package {
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
  
    [SWF(width="300", height="300", backgroundColor="#FFFFFF", frameRate="50")]    
     public class FlashTest extends Sprite {
        private const R:int = 0xDC2900;
        private const G:int = 0x8B7300;
        private const Y:int = 0xFFA53B;
        private var size:int = 15;
        private var dotsArr:Array = new Array();
        private var timer:Timer;
        private var cnt:int = 0;
        private var i:int;
        
        public function FlashTest(){
         var cells:MovieClip = drawCell(1,0xFFFFFF);//グリッドの色を背景色と同じにして隠す。
         stage.addChild(cells);
          for(i=0;i<dotsArr.length;i++){
            stage.addChild(dotsArr[i]);
          }
          
          timer = new Timer(100);
          timer.addEventListener("timer", timerHandler);
          timer.start();
        }
        
        private function timerHandler(e:TimerEvent):void {
          dotsArr[cnt].moveTorigger();
          cnt++;
          if(cnt == dotsArr.length){
            stage.removeEventListener("timer", timerHandler);
            timer.stop();
          }
        }
      
        //セルを描画 -これはもう素直にGridクラスとかにしちゃうべきだった。
        private function drawCell(bold:int,color:int):MovieClip{
          var cells:MovieClip = new MovieClip();
          var cellsArr:Array = [[0,0,0,R,R,R,R,R,0,0,0,0]
                               ,[0,0,R,R,R,R,R,R,R,R,R,0]
                               ,[0,0,G,G,G,Y,Y,G,Y,0,0,0]
                               ,[0,G,Y,G,Y,Y,Y,G,Y,Y,Y,0]
                               ,[0,G,Y,G,G,Y,Y,Y,G,Y,Y,Y]
                               ,[0,G,G,Y,Y,Y,Y,G,G,G,G,0]
                               ,[0,0,0,Y,Y,Y,Y,Y,Y,Y,0,0]
                               ,[0,0,G,G,R,G,G,G,0,0,0,0]
                               ,[0,G,G,G,R,G,G,R,G,G,G,0]
                               ,[G,G,G,G,R,R,R,R,G,G,G,G]
                               ,[Y,Y,G,R,Y,R,R,Y,R,G,Y,Y]
                               ,[Y,Y,Y,R,R,R,R,R,R,Y,Y,Y]
                               ,[Y,Y,R,R,R,R,R,R,R,R,Y,Y]
                               ,[0,0,R,R,R,0,0,R,R,R,0,0]
                               ,[0,G,G,G,0,0,0,0,G,G,G,0]
                               ,[G,G,G,G,0,0,0,0,G,G,G,G]
                              ];
                              
          for(var v:int=0;v<cellsArr.length;v++){
             for(var f:int=0;f<cellsArr[v].length;f++){
               var cell:MovieClip = new MovieClip();
               cell.graphics.lineStyle(bold,color);
               cell.graphics.drawRect(0 ,0 ,size ,size);
               cell.x = size*f; 
               cell.y = size*v;
               cells.addChild(cell)                  
               if(cellsArr[v][f] != 0){
                  var d:MovieClip = new dot(cellsArr[v][f]
                                        ,size
                                        ,Math.random() * stage.stageWidth
                                        ,Math.random() * stage.stageHeight 
                                        ,cell.x
                                        ,cell.y);
                  dotsArr.push(d);
               }
             }
          }
          return cells;
        }
        
    }
}

   import flash.display.MovieClip;
   import flash.events.MouseEvent;
   import flash.events.Event;
   class dot extends MovieClip{
     private var gX:int; //ゴール地点X
     private var gY:int; //ゴール地点Y
     
     public function dot(color:int
                         ,size:int
                         ,_x:int
                         ,_y:int
                         ,_gX:int
                         ,_gY:int):void{
        gX = _gX;
        gY = _gY;
        x = _x;
        y = _y;
                 
        graphics.beginFill(color, 1);
        graphics.drawRect(0,0,size,size);
        graphics.endFill();
          
        addEventListener(Event.ENTER_FRAME, fallingDot);
     }
     //落下処理もメンバメソッド化
     public function fallingDot(e:Event):void
     {
     	if(y + height < stage.stageHeight)
     	{
     		y += 3;
        	}else{
        		y = stage.stageHeight - height;
           	removeEventListener(Event.ENTER_FRAME, fallingDot);
   		}
     }	
     
     //移動を始める前に落下処理を止めさせる
     public function moveTorigger():void
     {
     	removeEventListener(Event.ENTER_FRAME, fallingDot);
        addEventListener(Event.ENTER_FRAME ,movingDot);
     }
     
     public function movingDot(e:Event):void{
        y = (y + gY) /2;
        x = (x + gX) /2;
       
        if(Math.round(y) == gY && Math.round(x) == gX){
           y = gY;
           x = gX;
          removeEventListener(Event.ENTER_FRAME ,movingDot);
        }
     }
  }