2012-02-22 171 views
0
var PlayerScore:TextField = new TextField(); 

//Here we add the new textfield instance to the stage with addchild() 
_canvas.addChild(PlayerScore); 


var myFormat:TextFormat = new TextFormat(); 
myFormat.size = 30; 

PlayerScore.defaultTextFormat = myFormat; 

PlayerScore.text = _player_score.toString(); 
PlayerScore.width = 250; 
PlayerScore.x = 70; 
PlayerScore.y = -20; 
PlayerScore.textColor = 0xFFFFFF; 

我在構造函數中使用這個訪問影片剪輯中的另一種方法

我如何使用

PlayerScore.text = _player_score.toString(); 

在另一種方法?

+1

你是什麼意思的「使用」?你的意思是如何從其他方法/類設置文本? – Eugeny89 2012-02-22 11:22:37

+0

你可以使它成爲一個靜態變量 – Summer 2012-02-22 23:51:59

+0

「你的意思是如何設置其他方法/類的文本?」是 – John 2012-02-23 13:46:18

回答

0

使用此方法{ PlayerScore.text = _player_score.toString();

分配一個變量:例如

var cash:int = 500; // cash is the variable// 

    showTextBTN.addEventListener(MouseEvent.CLICK, variableTotext); 

    function variableTotext(){ 
    Money.text = cash.toString();// the variable cash will output in Money text box 
    } 

添加一個按鈕或MC到階段,給它「showTextBTN」的一個實例名。 然後添加一個實例名稱爲「Money」的動態文本框。 在動作時間軸(as3)中添加上面的代碼; 編譯/運行電影