开发者

Flash Action Script 3 function scope

go_btn.addEventListener(MouseEvent.CLICK, getPlayerName);

var playerName;
function getPlayerName(开发者_Python百科e:MouseEvent)
{
    playerName = playerName_txt.text;
}

trace(playerName);

Hi, is there any way to have this work. I want to update a variable outside the scope of the function.

Thanks


Put your code into a class, instead of a blob of code on a frame or on a MovieClip. All methods inside a class have easy access to any member variables defined on that class.


Give it a value outside of the function, then change it inside the function:

go_btn.addEventListener(MouseEvent.CLICK, getPlayerName);

var playerName:String;
playerName = "nono";
playerName_txt.text = "blah";

function getPlayerName(e:MouseEvent)
{
    playerName = playerName_txt.text;

}

trace(playerName);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜