变量变化检测actionscript 3.0
假设我有 a ,它可以是 0(假)或 1(真)。有没有办法检测变量何时更改为 1(真)。我想要一个声音在它成为现实时播放,但只播放一次。
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有内置机制来发出更改值的信号,但您可以自己轻松实现:为您的变量创建一个 setter 函数,并让它在设置值时调用
playSound()
方法1.您可能还想查看 观察者模式 如果你打算更大规模地做这样的事情。
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.You might also want to check out the Observer pattern if you're going to do things like this on a larger scale.
看一下
mx.绑定.utils.BindingUtils
take a look at
mx.binding.utils.BindingUtils