I have an AS3 function that runs when a URLRequest fails. I need to be able to use this function to assign global variables that I can then check against using other functions. How do I assign global variables inside of a function?
Thanks!
Edit:This is the variable (soundFile2Exist) I am trying to get outside of my function:
function onIOError(e:IOErrorEvent):void
{
var soundFile2exist = null;
trace (soundFile2exist);
}
I am not using my code inside of a packge. Is there still a way to do this?
function playMusic(evt:MouseEvent):void
{
channel = myMusic.play(songPosition);
if (soundFile2exist != null) {
channel2 = myMusic2.play(channel.position);
}
myTimer.start();
btnPlay.mouseEnabled = false;
trace (soundFile2exist);
}
If your code is “not in a package” (like in a frame script on a timeline), any variables you declare on the same level, same scope, as your functions will be accessible to the functions in that scope, so you could do something in the lines of this:
In other situations, static variables of a class can be used in place of global variables.