views:

71

answers:

2
go_btn.addEventListener(MouseEvent.CLICK, getPlayerName);

var playerName;
function getPlayerName(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

A: 

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.

davr
A: 

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);
redconservatory