通过 ProgressEvent 更新标签上的字节数

发布于 2024-07-21 22:11:02 字数 519 浏览 4 评论 0原文

我有 main.mxml 和一个外部类 com.audio.AudioPlayer.as

AudioPlayer 加载一个音频文件,并有一个用于计算 bytesLoaded 和 bytesTotal 的事件。

我想在将 bytesLoaded 信息从 ProgressEvent.PROGRESS 加载到 main.mxml 上的标签时不断推送它,

snd.addEventListener(ProgressEvent.PROGRESS, listenProgress);


    private function listenProgress(event:ProgressEvent):void
    {
        progressID.text = event.bytesLoaded + " / " + event.bytesTotal;
    }

我找不到从 AudioPlayer 内部定位 main.mxml 中的标签控件并不断更新的方法字节数。

任何帮助,非常感谢...

I have main.mxml and an external class com.audio.AudioPlayer.as

AudioPlayer loads an audio file and has an event for counting bytesLoaded and bytesTotal.

I would like to push the bytesLoaded information continuously as its being loaded into a label on main.mxml from the ProgressEvent.PROGRESS

snd.addEventListener(ProgressEvent.PROGRESS, listenProgress);


    private function listenProgress(event:ProgressEvent):void
    {
        progressID.text = event.bytesLoaded + " / " + event.bytesTotal;
    }

I can't find a way to target the label control in main.mxml, from inside AudioPlayer and to continuously update the byte count.

Any help, much appreciated...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

玻璃人 2024-07-28 22:11:02

在 AudioPlayer 中创建一个可绑定变量,并在事件处理程序中将其设置为正确的值。

在您的 mxml 中,将标签的文本绑定到该值。

Create a bindable variable in AudioPlayer and set it to the correct value in your event handler.

In your mxml, bind the label's text to that value.

柠栀 2024-07-28 22:11:02

好吧,我想出了一个解决办法。 在 AudioPlayer.as 中,我声明:

public var snd:Sound = new Sound();

在 main.mxml 中,我添加了 snd 的事件侦听器:

newAudio.snd.addEventListener(Event.COMPLETE, onSoundComplete);
newAudio.snd.addEventListener(ProgressEvent.PROGRESS, listenProgress);

... 这样做时,我可以通过声明更新我的 mxml 控件:

[Bindable] private var progUpdate:String;

<mx:Label text="{progUpdate}" x="254.75" y="46" width="506.5" />

所以基本上我只是将 eventListeners 从 AudioPlayer 类移动到文档类中。

ok I figured out a work around. In AudioPlayer.as I declared:

public var snd:Sound = new Sound();

in main.mxml I added the event listeners for snd:

newAudio.snd.addEventListener(Event.COMPLETE, onSoundComplete);
newAudio.snd.addEventListener(ProgressEvent.PROGRESS, listenProgress);

... in doing so I can update my mxml control by declaring:

[Bindable] private var progUpdate:String;

<mx:Label text="{progUpdate}" x="254.75" y="46" width="506.5" />

so basically I just moved the eventListeners from the AudioPlayer class and into the document class.

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