• 一个loader加载多个swf


    var _swfLoader:Loader;
    var _swfRequest:URLRequest;
     
    var _swfPathArr:Array = new Array("00.swf", "01.swf", "02.swf");
     
    var _swfClipsArr:Array = new Array();
    var _swfTempClip:MovieClip;
    var _loadedSWFs:int;
     
     
    startLoading(_swfPathArr);
     
    function startLoading(pathArr:Array):void {
        _swfLoader = new Loader();
        _swfRequest = new URLRequest();
       
        loadSWF(pathArr[0]);
    }
     
    function loadSWF(path:String):void {
        setupListeners(_swfLoader.contentLoaderInfo);
       
        _swfRequest.url = path;
        _swfLoader.load(_swfRequest);
    }
     
    function setupListeners(dispatcher:IEventDispatcher):void {
        dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
    }
     
    function currentSwfProgress(event:ProgressEvent):void {
        var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
        // swfPreloader.percentTF.text = _perc + "%";
    }
     
     
    function onSwfComplete(event:Event):void {
        event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
        event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
     
        _swfTempClip = event.target.content;
        _swfTempClip.customID = _loadedSWFs;
        _swfClipsArr.push(_swfTempClip);
       
        if(_loadedSWFs <_swfPathArr.length - 1) {
            _loadedSWFs++;
            loadSWF(_swfPathArr[_loadedSWFs]);
        } else {
            _swfLoader.unloadAndStop();
            _swfLoader = null;
            onCompletePreloading();
        }
    }
     
    function onCompletePreloading():void {
        contentContainer.addChild(_swfClipsArr[0]);
       
        news_btn.addEventListener(MouseEvent.CLICK, setContent);
        portfolio_btn.addEventListener(MouseEvent.CLICK, setContent);
        contact_btn.addEventListener(MouseEvent.CLICK, setContent);
    }
     
    function setContent(event:MouseEvent):void {
        var _swfToAdd:MovieClip;
       
        switch(event.target.name) {
            case "news_btn":
            _swfToAdd = _swfClipsArr[0];
            break;
           
            case "portfolio_btn":
            _swfToAdd = _swfClipsArr[1];
            break;
           
            case "contact_btn":
            _swfToAdd = _swfClipsArr[2];
            break;
        }
       
        contentContainer.removeChildAt(contentContainer.numChildren-1);
        contentContainer.addChild(_swfToAdd);
        trace(_swfToAdd.customID);
    }
    http://www.beautifycode.com/the-finer-art-of-loading-2-handling-multiple-swfs
  • 相关阅读:
    10. 正则表达式匹配
    124. 二叉树中的最大路径和。 递归
    1028. 从先序遍历还原二叉树。 深搜
    1014. 最佳观光组合. 转变思路
    297. 二叉树的序列化与反序列化.
    1300. 转变数组后最接近目标值的数组和. 二分
    15. 三数之和. 双指针法⭐
    1. 两数之和. 哈希表
    739. Daily Temperatures. 单调栈
    面试题46. 把数字翻译成字符串. 递归
  • 原文地址:https://www.cnblogs.com/602147629/p/3909611.html
Copyright © 2020-2023  润新知