变量变化检测actionscript 3.0

发布于 2024-12-15 06:36:45 字数 91 浏览 4 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守不住的情 2024-12-22 06:36:45

没有内置机制来发出更改值的信号,但您可以自己轻松实现:为您的变量创建一个 setter 函数,并让它在设置值时调用 playSound() 方法1.

private var _myVariable : int = 0;

public function set myVariable (n:int) : void
{
    _myVariable = n;
    if (n == 1) playSound();
}

您可能还想查看 观察者模式 如果你打算更大规模地做这样的事情。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文