In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

[Progression4] LoaderList, SerialList, ParallelListの比較

Progression4を利用した外部画像読み込み
* LoaderList, SerialList, ParallelListの比較
* 
* SerialListは直列で、コマンド単位でのみ進捗を表示可能
* LoaderListは直列で、画像読み込みに応じた進捗を表示可能
* ParallelListは並列のため読み込みは高速、進捗報告はその後のバージョンアップで可能になった
/**
 * Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xtLt
 */

/**
 * Progression4を利用した外部画像読み込み
 * LoaderList, SerialList, ParallelListの比較
 * 
 * SerialListは直列で、コマンド単位でのみ進捗を表示可能
 * LoaderListは直列で、画像読み込みに応じた進捗を表示可能
 * ParallelListは並列のため読み込みは高速、進捗報告はその後のバージョンアップで可能になった
 */
package {
    import flash.events.*;
    import flash.net.*;
    import flash.system.Security;
    import flash.utils.*;
    import jp.progression.casts.*;
    import com.bit101.components.*
    import jp.progression.commands.lists.*;
    import jp.progression.commands.net.*;
    
    public class Main extends CastDocument {
        
        private var progress:ProgressBar;
        private var label:Label;
        
        override protected function atReady():void  {
            Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
            Security.loadPolicyFile("http://farm4.static.flickr.com/crossdomain.xml");
            new PushButton(this, 10, 10, "SerialList", startSerialList);
            new PushButton(this, 150, 10, "LoaderList", startLoaderList);
            new PushButton(this, 300, 10, "ParanelList", startParallesList);
            progress = new ProgressBar(this, 10, 50);
            label = new Label(this, 10, 70);
        }
        
        private function startSerialList(e:Event = null):void {
            var list:SerialList = new SerialList();
            for (var i:int = 0; i < IMG_FILES.length; i++) {
                list.addCommand( new LoadBitmapData(new URLRequest(IMG_FILES[i] + "?" + Math.random() * 10000), {cacheAsResource:false}));
            }
            list.onPosition = function():void {
                progress.value = list.position / list.numCommands;
                label.text = list.position + "/" +  list.numCommands + " with SerialList";
            }
            var oldTimer:int = getTimer();
            list.onComplete = function():void {
                label.text = "Load Time : " + Math.round(getTimer() - oldTimer) / 1000 + "sec with SerialList";
            }
            list.execute();
        }
        
        private function startLoaderList(e:Event = null):void{
            var list:LoaderList = new LoaderList();
            for (var i:int = 0; i < IMG_FILES.length; i++) {
                list.addCommand( new LoadBitmapData(new URLRequest(IMG_FILES[i] + "?" + Math.random() * 10000), {cacheAsResource:false}));
            }
            list.onProgress = function():void {
                progress.value = list.percent / 100;
                label.text = Math.round(list.percent) + "% with LoaderList";
            }
            var oldTimer:int = getTimer();
            list.onComplete = function():void {
                label.text = "Load Time : " + Math.round(getTimer() - oldTimer) / 1000 + "sec with LoaderList";
            }
            list.execute();
        }
        
        private function startParallesList(e:Event = null):void {
            
            var list:ParallelList = new ParallelList();
            for (var i:int = 0; i < IMG_FILES.length; i++) {
                list.addCommand( new LoadBitmapData(new URLRequest(IMG_FILES[i] + "?" + Math.random() * 10000), {cacheAsResource:false}));
            }
            label.text = "NOW LOADING with ParallelList"
            var oldTimer:int = getTimer();
            list.onComplete = function():void {
                label.text = "Load Time : " + Math.round(getTimer() - oldTimer) / 1000 + "sec with ParallelList";
            }
            list.onUpdate = function():void {                progress.value = list.count / list.total;                label.text = Math.round(list.count / list.total * 100) + "% with LoaderList";            }
            list.execute();
        }
        
        private static const IMG_FILES:Array = [
            "http://farm3.static.flickr.com/2544/3999799072_29522c4ded_m.jpg",
            "http://farm3.static.flickr.com/2544/3999799072_29522c4ded_m.jpg",
            "http://farm4.static.flickr.com/3449/3934552946_ed75627ca0_m.jpg",
            "http://farm3.static.flickr.com/2613/3933770677_78c6ed5c99_m.jpg",
            ];
    }
}