package { import flash.display.MovieClip; import flash.display.Sprite; import fl.controls.Button; import flash.events.MouseEvent; public class Fifty extends Sprite { private var btn:Button; private var btnName:int = 1; private var ifnumber:Number = 1; private var labelArr:Array = []; private var label1:Number = Math.floor(Math.random()*50)+1; public function Fifty() { // constructor code init(); //btnnameArr(); } private function init():void { btninit(); } private function btninit():void { labelArr.push(label1); for(var n:int=1;n<50;n++){ label1 = Math.floor(Math.random()*50)+1; if(labelArr.indexOf(label1,0)==-1){ labelArr.push(label1); }else{ n--; label1 = Math.floor(Math.random()*50)+1; } //btn.label = labelArr.shift(); } for (var i:int = 1; i <= 10; i ++ ) { for (var j:int = 1; j <= 5; j++ ) { btn = new Button(); //btn.label = String(Math.round(Math.random()*49)+1); btn.label = labelArr.shift(); btn.x = i * 50; btn.y = j * 30 ; btn.width = 30; addChild(btn); //btnName++; btn.addEventListener(MouseEvent.CLICK, onAllBtnClickHandler); } } } private function btnnameArr():void { } private function onAllBtnClickHandler(e:MouseEvent):void { if (e.target.label == ifnumber) { trace("对了") e.target.visible = false; ifnumber++; } //trace(e.target.label); } } }