I'm new in as3. I'm trying to use variable which i assign a value from a function. But the variable outside the function always shown as a null value. I tried using the global variable way, but seems not working too.
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete(event:Event)
{
// Save Kongregate API reference
kongregate = event.target.content;
// Connect to the back-end
kongregate.services.connect();
// You can now access the API via:
// kongregate.user
// kongregate.scores
// kongregate.stats
// etc...
username = kongregate.services.getUsername();
trace("inside:"+username);
}
trace("outside:"+username);
How to use the variable a outside the function?
The output:
outside:
Alert: Kongregate API shadow services loaded due to local testing. API will load when the game is uploaded.
Kongregate API: IKongregateServices.connect()
inside:Guest