FLASH中外链的歌曲,如何做一个动态文本显示缓冲百分比%
发布网友
发布时间:2024-09-28 09:32
我来回答
共1个回答
热心网友
时间:2024-09-30 07:47
AS3文档中有相关的代码,你可以自己理解一下。
package {
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
public class Sound_loadExample extends Sprite {
private var snd:Sound = new Sound();
private var statusTextField:TextField = new TextField();
public function Sound_loadExample(){
statusTextField.autoSize = TextFieldAutoSize.LEFT;
var req:URLRequest = new URLRequest("http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3");
try {
snd.load(req);
snd.play();
}
catch (err:Error) {
trace(err.message);
}
snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
snd.addEventListener(ProgressEvent.PROGRESS, progressHandler);
this.addChild(statusTextField);
}
private function progressHandler(event:ProgressEvent):void {
var loadTime:Number = event.bytesLoaded / event.bytesTotal;
var LoadPercent:uint = Math.round(100 * loadTime);
statusTextField.text = "Sound file's size in bytes: " + event.bytesTotal + "\n"
+ "Bytes being loaded: " + event.bytesLoaded + "\n"
+ "Percentage of sound file that is loaded " + LoadPercent + "%.\n";
}
private function errorHandler(errorEvent:IOErrorEvent):void {
statusTextField.text = "The sound could not be loaded: " + errorEvent.text;
}
}
}