Reputation: 85
Lets say I have a which can be either 0 (false) or 1 (true). Is there a way to detect when the variable is CHANGING to 1 (true). I want a sound to play whenever it becomes true, but only once.
Thanks for any help!
Upvotes: 0
Views: 862
Reputation: 22604
There is no built-in mechanism that signals a changed value, but you can easily implement this yourself: Create a setter function for your variable and have it call the playSound()
method, whenever the value is set to 1.
private var _myVariable : int = 0;
public function set myVariable (n:int) : void
{
_myVariable = n;
if (n == 1) playSound();
}
You might also want to check out the Observer pattern if you're going to do things like this on a larger scale.
Upvotes: 6