flash on 2010-2-4

by hacker_9p8x8mco
♥0 | Line 63 | Modified 2010-02-05 02:03:00 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_9p8x8mco ( http://wonderfl.net/user/hacker_9p8x8mco )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4oBt
 */

package{
	import com.bit101.components.PushButton;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class MorningBlueDragon extends Sprite{
		public static const SLOT_NUM:int = 3;
		public static const SLOT_SIZE:int = 140;
		private static const SLOT_TEXT:Array = 
		[["朝","昼","夕","夜"],
		["青","赤","黄","白","黒"],
		["龍","虎","雀","亀"]];
		private var _slots:Array;

		public function MorningBlueDragon(){
			_slots = [];
			for(var i:int = 0; i < SLOT_NUM; i++){
				var slot:Slot = new Slot((i * SLOT_SIZE) + 10,10);
				slot.setText(SLOT_TEXT[i][0]);
				_slots.push(slot);
				addChild(slot);
			}

		
			new PushButton(this,SLOT_SIZE + 30,SLOT_SIZE + 20,"click!",clickButton);
			addEventListener(Event.ENTER_FRAME,update);
		}

		private function clickButton(e:Event):void{
			var i:int;
			for(i = 0; i < SLOT_NUM; i++){
				if (_slots[i].roll){
					_slots[i].roll = false;
					break;
				}
			}
			if(i == SLOT_NUM){
				for(var j:int = 0;j < SLOT_NUM; j++){
					_slots[j].roll = true;
				}
			}
		}
	
		private function update(e:Event):void{
			for(var i:int = 0; i < SLOT_NUM; i++){
				if(_slots[i].roll){
					_slots[i].setText(SLOT_TEXT[i][Math.floor(SLOT_TEXT[i].length * Math.random())]);
				}
			}
		}
	}
}

import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

class Slot extends TextField{
	public var roll:Boolean;
	
	public function Slot(posx:int,posy:int){
		roll = false;
		x = posx; y = posy;
		width = height = MorningBlueDragon.SLOT_SIZE;
		border = true;borderColor = 0x000000;
		selectable = false;
	}

	public function setText(str:String):void{
		text = str;
		setTextFormat(new TextFormat(null,MorningBlueDragon.SLOT_SIZE));
	}
}