views:

161

answers:

2

Hi, 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...

A: 

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.

Marc Hughes
Hi Marc, so I've tried what you said. I did:AudioPlayer.as [Bindable] public var progUpdate:String; progUpdate = event.bytesLoaded + " / " + event.bytesTotal;Main.mxmlprivate var newAudio:AudioPlayer = new AudioPlayer(); progressID.text = newAudio.progUpdate;The text field doesn't update at all unfortunately. Could I have missed something?
Tomaszewski
A: 

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.

Tomaszewski