利用Flash AS3 制作Loading加载进度条


var request:URLRequest = new URLRequest("flashrek.swf");   
var loader:Loader = new Loader();   
  
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);   
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);   
  
function loadProgress(event:ProgressEvent):void {   
    var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;   
    percentLoaded = Math.round(percentLoaded * 100);   
    trace("Loading: "+percentLoaded+"%");   
}   
  
function loadComplete(event:Event):void {   
    trace("Complete");   
}   
  
loader.load(request);   
addChild(loader);  


这里要注意loader的load方法只接受URLRequest对象作为参数;另外就是ProgressEvent类,比较简单,看帮助就好了。

这里只是LOAD外部对象,如何做自身LOADING还要再研究研究,等有了答案再更新。

更新自身Loading


stop();   
import flash.display.LoaderInfo;   
import flash.events.ProgressEvent;   
import flash.text.TextField;   
var loadText:TextField=new TextField();   
addChild(loadText);   
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,myloadmovie);   
this.loaderInfo.addEventListener(Event.COMPLETE,myover);   
function myloadmovie(event:ProgressEvent):void {   
    var hl:Number=event.bytesLoaded/event.bytesTotal;   
    var n:Number=Math.round(hl*100);   
    loadText.text=n+"%";   
}   
function myover (event:Event):void {   
    this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS,myloadmovie);   
    nextFrame();   
}  

下面是另一种自身loading的方法


stop();   
import flash.display.LoaderInfo;   
import flash.events.ProgressEvent;   
import flash.text.TextField;   
var loadText:TextField=new TextField();   
loadText.x=220;   
loadText.y=200;   
addChild(loadText);   
myload.addEventListener(Event.ENTER_FRAME,onEnterFramee);   
function onEnterFramee (event:Event) {   
    if (framesLoaded==totalFrames) {   
        trace(1);   
        myload.removeEventListener(Event.ENTER_FRAME,onEnterFramee);   
        nextFrame();   
    }   
    else {   
        var percent:Number=root.loaderInfo.bytesLoaded/root.loaderInfo.bytesTotal;   
        var m:Number=Math.round(percent*100);   
        myload.gotoAndStop(m);   
        loadText.text=m+"%";   
    }   
}        //myload为场景中预设的loading动画的MC名字  


( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000355192{main}( ).../index.php:0
20.0001355480require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
31.391910192200require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
41.393110263344include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
51.485510814536get_template_part( ).../single.php:5
61.485510815056locate_template( ).../general-template.php:167
71.485510815152load_template( ).../template.php:643
81.485610815536require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
91.494510800648cwppos_show_review( ).../content-single.php:29

发表评论

电子邮件地址不会被公开。 必填项已用*标注