In Actionscript 2 I cannot access global class variables in a method being executed by setInterval(). The variable can be accessed in other methods fine. The workaround is to pass the variable in as a parameter on the setInterval() function, but it seems I should be able to access it without doing that. Here is an example of what I am running in to:
class Food {
private var drink:String = "Pepsi";
private var interval:Number;
// Constructor
public function Food() {
getDrink();
interval = setInterval(allDrinks, 500);
}
private function getDrink() {
// Returns "Pepsi"
trace(drink);
}
private function allDrinks() {
// Returns "undefined" instead of "Pepsi"
trace(drink);
}
}
I’d also like to note that I am using Flash player 8. Any help would be appreciated!