AS3:获取数组编号并将其添加到屏幕

时间:2014-06-17 13:42:11

标签: arrays actionscript-3 sorting placement

所以我目前有一个数组设置,在用户选择5个数字之前没有任何内容(总共有59个数字(数字在图表中))。所以现在我想知道是否有办法调用拾取的第一个数字并将其放在屏幕上的某个点然后是第二个,依此类推。这里只是我目前使用的一些代码。

var pickFive:Array = new Array (5);
var m_iNextElement:int = 0;

Game.board.btn_1.addEventListener(MouseEvent.CLICK, btn1);
Game.board.btn_2.addEventListener(MouseEvent.CLICK, btn2);
Game.board.btn_3.addEventListener(MouseEvent.CLICK, btn3);
Game.board.btn_4.addEventListener(MouseEvent.CLICK, btn4);
Game.board.btn_5.addEventListener(MouseEvent.CLICK, btn5);
Game.board.btn_6.addEventListener(MouseEvent.CLICK, btn6);


function btn1(event:MouseEvent):void{
    if(m_iNextElement <= 4){
    Game.board.btn_1.gotoAndStop(2);
    pickFive[m_iNextElement] = 1;
    m_iNextElement++;
    }
}

function btn2(event:MouseEvent):void{
    if(m_iNextElement <= 4){
    Game.board.btn_2.gotoAndStop(2);
    pickFive[m_iNextElement] = 2;
    m_iNextElement++;
    }
}

function btn3(event:MouseEvent):void{
    if(m_iNextElement <= 4){
    Game.board.btn_3.gotoAndStop(2);
    pickFive[m_iNextElement] = 3;
    m_iNextElement++;
    }
}

function btn4(event:MouseEvent):void{
    if(m_iNextElement <= 4){
    Game.board.btn_4.gotoAndStop(2);
    pickFive[m_iNextElement] = 4;
    m_iNextElement++;
    }
}

function btn5(event:MouseEvent):void{
    if(m_iNextElement <= 4){
    Game.board.btn_5.gotoAndStop(2);
    pickFive[m_iNextElement] = 5;
    m_iNextElement++;
    }
}

function btn6(event:MouseEvent):void{
    if(m_iNextElement <= 4){
    Game.board.btn_6.gotoAndStop(2);
    pickFive[m_iNextElement] = 6;
    m_iNextElement++;
    }
}

1 个答案:

答案 0 :(得分:0)

var b1:TextField = new TextField();
var myFont = new Font1();
var myFormat:TextFormat = new TextFormat();
myFormat.size = 45;
myFormat.font = myFont.fontName;
myFormat.align = TextFormatAlign.CENTER;
b1.embedFonts = true;
b1.antiAliasType = AntiAliasType.ADVANCED
    if(pickFive[0] != null){
        trace(Game.NumberBoard_mc.Pick5['btn_' + pickFive[0]].name);
        Game.NumberBoard_mc.Pick5['btn_' + pickFive[0]];
        b1.defaultTextFormat = myFormat;
        b1.text = pickFive[0];
        b1.x = 478;
        b1.y = 103;
        addChild(b1);
    }