开发者

Flash Action Script 3 function scope

开发者 https://www.devze.com 2022-12-23 00:45 出处:网络
go_btn.addEventListener(MouseEvent.CLICK, getPlayerName); var playerName; function getPlayerName(开发者_Python百科e:MouseEvent)
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

精彩评论

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