[問題] AS3多按鈕創建,請教該怎麼修改會比較好?
小弟自己玩as3
光是創建點擊會變色的按鈕,就想破我的頭
不好意思直接問該怎麼寫
花了好久時間,今天終於寫出來
但覺得我的寫法,好像每按一次物件就越來越多
想請教各位先進,應該怎麼修改,程式會比較好呢
var s:int = 15;//使用者輸入數字
var I:int = 1;
var textFormat:TextFormat = new TextFormat("Adobe 繁黑體 Std B",30);
textFormat.align = "center";
var btn_name:String;
var squarehit = new Sprite();
squarehit.graphics.beginFill(0xFFFFBB);
squarehit.graphics.drawRoundRect(0,0,60,60,20);
squarehit.graphics.endFill();
for (var j=1; j<=s/5; j++)
{
for (var i = 1; i <=5; i++)
{
var square = new Sprite();
square.graphics.beginFill(0xCCCCCC);
square.graphics.drawRoundRect(0,0,60,60,20);
square.graphics.endFill();
var num:TextField = new TextField();
num.defaultTextFormat = textFormat;
num.text = -5 + i + 5 * j;
num.x = 0;
num.y = 9;
num.width = square.width;
num.height = square.height;
var mc:MovieClip = new MovieClip();
mc.addChild( square );
mc.addChild( num );
var btn:SimpleButton = new SimpleButton();
btn_name = String(I);
btn.name = btn_name;
btn.upState = mc;
btn.overState = mc;
btn.downState = mc;
btn.hitTestState = mc;
btn.x = i * 80 - 30;
btn.y = (stage.stageHeight/2-square.height/2+(j*80))-s/5*40;
addChild( btn );
I++;
}
}
addEventListener(MouseEvent.CLICK, btnclick);
function btnclick(event:MouseEvent):void
{
var num:TextField = new TextField();
num.defaultTextFormat = textFormat;
num.x = 0;
num.y = 9;
num.width = square.width;
num.height = square.height;
num.text = event.target.name;
var mc:MovieClip = new MovieClip();
mc.addChild( squarehit );
mc.addChild( num );
var btn:SimpleButton = new SimpleButton();
btn.upState = mc;
btn.x = event.target.x;
btn.y = event.target.y;
addChild( btn);
}
//以下是使用者輸入5的倍數,還沒想好...
/*function makeClickListener(I:int) {
return function(evt:MouseEvent) {
trace(I);
var subj:int;
subj=(I+5-i)/5;
num.text = String( -5 + i + 5 * subj);
mc.addChild( squarehit );
mc.addChild( num );
btn.x = i * 80 - 30;
btn.y = (stage.stageHeight/2-square.height/2+(subj*80))-s/5*40;
addChild( btn );
};
}*/
/*for (var k=1; k<=s%5; k++)
{
var square1:Sprite = new Sprite();
square1.graphics.beginFill(0xCCCCCC);
square1.graphics.drawRoundRect(0,0,60,60,20);
square1.graphics.endFill();
square1.x = k * 80 - 30;
square1.y = (stage.stageHeight/2-square1.height/2+(j*80))-s/5*40;
addChild(square1);
var num1:TextField = new TextField();
num1.defaultTextFormat = textFormat;
num1.text = -11 + i + 5 * j + k;
num1.x = k * 80 - 50;
num1.y = (stage.stageHeight/2-square1.height/2+(j*80))-s/5*40+8;
addChild(num1);
fanhaotextArray.push(num1);
}*/
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.105.145.158
※ 文章網址: https://www.ptt.cc/bbs/Flash/M.1438069512.A.82E.html
※ 編輯: siesst50213 (120.105.145.188), 07/28/2015 15:47:42
推
07/28 17:59, , 1F
07/28 17:59, 1F
→
07/28 18:00, , 2F
07/28 18:00, 2F
→
07/28 18:00, , 3F
07/28 18:00, 3F
→
07/28 18:00, , 4F
07/28 18:00, 4F
→
07/28 18:01, , 5F
07/28 18:01, 5F
推
07/28 18:23, , 6F
07/28 18:23, 6F
→
07/28 18:23, , 7F
07/28 18:23, 7F
推
07/28 18:48, , 8F
07/28 18:48, 8F
推
07/28 19:48, , 9F
07/28 19:48, 9F
Flash 近期熱門文章
PTT數位生活區 即時熱門文章