8-bit mate
8-bit mate

Reputation: 85

Variable change detection actionscript 3.0

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

Answers (2)

www0z0k
www0z0k

Reputation: 4434

take a look at mx.binding.utils.BindingUtils

Upvotes: 0

weltraumpirat
weltraumpirat

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

Related Questions