首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Flash >

念写一个好的队列加载器,没想到FLASH 自带的HASHMAP 实在太慢了

2012-12-21 
想写一个好的队列加载器,没想到FLASH 自带的HASHMAP 实在太慢了我们都知道在高数据量的时候, 用SHIFT来剔

想写一个好的队列加载器,没想到FLASH 自带的HASHMAP 实在太慢了
我们都知道在高数据量的时候, 用SHIFT来剔除对象, 或者用SPLICE 会很慢
因此我想写一个好的队列加载器,
但是没想到, HASHMAP如此之慢
唉 只能放弃这个思路了, 还不如简单的ARRAY的队列快
唉 杯具~~

package com{import flash.display.Loader;import flash.display.LoaderInfo;import flash.display.Sprite;import flash.events.Event;import flash.events.IOErrorEvent;import flash.events.SecurityErrorEvent;import flash.net.URLRequest;import flash.utils.Dictionary;/** * 队列加载器, 失败啊, 没想到HASHMAP, 如此之慢 * @author guwanyuan *  */public class QueenLoader extends Sprite{/** * 清理后的标记URL地址  */public static const CLEAR_URL:String = "";public function QueenLoader(){super();urlDic = new Dictionary();}public function addLoaderItem(url:String):void{var index:int = offset + loaderList.length + list.length;urlDic[url] = index;list.push(url);if(!isLoader)nextLoader();}public function deleteLoaderItem(url:String, cancel:Boolean = false):void{trace("delete", url)var index:int = urlDic[url];var idx:int = index - offset;var loaderlistLeng:int = loaderList.length;if(idx < loaderlistLeng){var leng:int = loaderlistLeng - idx;loaderList[leng] = CLEAR_URL;}else{var listIndex:int = idx - loaderlistLeng;list[listIndex] = CLEAR_URL;}}private function startLoad(url:String):void{trace(url);isLoader = true;var loader:Loader = new Loader();loader.load(new URLRequest(url));loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIoError);loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);}private function onSecurityError(e:SecurityErrorEvent):void{isLoader = false;nextLoader();}private function onIoError(e:IOErrorEvent):void{isLoader = false;nextLoader();}private function loaderComplete(e:Event = null):void{if(e)LoaderInfo(e.target).removeEventListener(Event.COMPLETE, loaderComplete);isLoader = false;nextLoader();}private function nextLoader():void{var url:String = CLEAR_URL;while(url == CLEAR_URL){reverseList();url = loaderList.pop();offset++;}if(url)startLoad(url);}private function reverseList():void{if(loaderList.length <= 0){loaderList = list.reverse();list = [];}}private var currentIndex:int = 0;private var isLoader:Boolean = false;private var offset:int = 0;private var urlDic:Dictionary;private var list:Array = [];private var loaderList:Array = [];}}

热点排行