2014-04-30 32 views
0

我想將文本添加到工作按鈕。目前,下面的代碼在0,0而不是在精靈按鈕上打印文本。Sprite文本位置不正確

soundButton.graphics.beginFill(0xFFCC00); 
    soundButton.graphics.drawRect(0,900, 200, 50); 
    soundButton.graphics.endFill(); 
    this.addChild(soundButton); 

    var soundtext:TextField = new TextField(); 
    soundtext.text ="Sound On"; // default value 
    soundButton.addChild(soundtext); 
    soundButton.addEventListener(MouseEvent.CLICK,sound_CLICK); 

此外,我想添加代碼到下面的監聽器,讓按鈕文本反映布爾doSound的狀態。

private function sound_CLICK (event:MouseEvent):Void { 
      doSound = !doSound; 
      // swap sprite button text Sound on/Sound off 

    } 

回答

0

使用文本字段的x和y屬性來定位按鈕上的文本?

如果有什麼我不知道更新我的答案。

+0

Duh。出於某種原因,我認爲x,y是從精靈中繼承而來的。非常感謝你! – Jocala