4pxモグラ叩き
/**
* Copyright sakusan393 ( http://wonderfl.net/user/sakusan393 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2KZ6
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.events.*;
import flash.display.Sprite;
import flash.text.*;
[SWF(backgroundColor="0x000000", frameRate="30", width="465", height="465")]
public class FlashTest extends Sprite {
private var _w:int
private var _h:int
private var _timer:Timer = new Timer(1000);
private var _spArray:Array = [];
private var _tf:TextField = new TextField();
private var _count:int;
public function FlashTest() {
// write as3 code here..
this.addEventListener(Event.ADDED_TO_STAGE , init);
}
public function init(e:Event):void{
this.removeEventListener(Event.ADDED_TO_STAGE , init);
_w = stage.stageWidth;
_h = stage.stageHeight;
_tf.background = true;
_tf.backgroundColor = 0xFFFFFF;
_tf.width = 100;
_tf.height = 20;
_tf.alpha = 0.8;
_tf.autoSize = "right";
_tf.wordWrap = false;
_tf.x = _w/2 - _tf.width;
_tf.text = String(_count);
var _bmd:BitmapData = new BitmapData(465,465,false,0);
var _bm:Bitmap = new Bitmap(_bmd);
addChild(_bm);
addChild(_tf);
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
_timer.start();
var i:int;
var j:int;
for(i = 0; i < _w; i+=6){
for(j = 0; j < _h; j+=6){
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFFFF00);
sp.graphics.drawRect(0,0,2,2);
sp.graphics.endFill();
sp.buttonMode = true;
sp.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(sp);
sp.x = i;
sp.y = j;
_spArray.push(sp);
sp.visible = false;
_bmd.setPixel(i,j,0x666666);
_bmd.setPixel(i+1,j,0x666666);
_bmd.setPixel(i,j+1,0x666666);
_bmd.setPixel(i+1,j+1,0x666666);
}
}
trace(this.numChildren);
}
public function clickHandler(e:MouseEvent){
_count++;
_tf.text = String(_count);
}
public function timerHandler (e:TimerEvent):void {
var i:int;
var maxNum:int = _spArray.length;
for(i = 0; i < maxNum; i++){
_spArray[i].visible = false;
}
for(i = 0; i < 100; i++){
_spArray[(0 | Math.random()*maxNum)].visible = true;
}
trace((0 | Math.random()*maxNum));
}
}
}