以文本方式查看主题

-  康柏仕电脑学院  (http://combss.com/bbs/index.asp)
--  FLASH闪客交流区  (http://combss.com/bbs/list.asp?boardid=29)
----  [技巧]判断外部影片载入进度的两种方法  (http://combss.com/bbs/dispbbs.asp?boardid=29&id=743)

--  作者:轻轻风聆
--  发布时间:2007/8/24 8:46:35
--  判断外部影片载入进度的两种方法

方法一(推荐):MovieClipLoader方法

var mcContainer:MovieClip = this.createEmptyMovieClip("myMC", this.getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mcListener:Object = new Object();
mcListener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
trace(Math.floor((bytesLoaded/bytesTotal)*100)+"%");
}
mcListener.onLoadInit = function(target:MovieClip):Void {
trace(target._name + " loadedComplete");
}
mcLoader.addListener(mcListener);
mcLoader.loadClip("picImg/pic1.jpg", "myMC");


//方法二:onEnterFrame方法

this.createEmptyMovieClip("tempMC", this.getNextHighestDepth());
this.createEmptyMovieClip("loaderMC", this.getNextHighestDepth());
loaderMC.loadMovie("picImg/pic1.jpg");
tempMC.onEnterFrame = function() {
var loaded = loaderMC.getBytesLoaded();
var loadTotal = loaderMC.getBytesTotal();
trace(int((loaded/loadTotal)*100)+"%");
//此处很奇异,判断是否加载完要用((loaded/loadTotal) == 1)而不能用(loaded == loadTotal)
if((loaded/loadTotal) == 1){
delete this.onEnterFrame;
trace("loadedComplete");
}
}