- package com
- {
- import com.greensock.events.LoaderEvent;
- import com.greensock.loading.ImageLoader;
- import com.greensock.loading.LoaderMax;
- import com.greensock.loading.XMLLoader;
- import flash.text.TextField;
- import flash.display.MovieClip;
- import flash.events.Event;
- /**
- * @author
- */
- public class Data extends MovieClip
- {
- public var _stageHeight : int = -246;
- private var dataLoader : XMLLoader;
- public static var p_w_picpathObj : Object = {}; //图片配置信息
- public static var p_w_picpathUrlArr : Array = []; //图片地址
- public var p_w_picpathArr : Array = []; //图片对像数组
- private var p_w_picpathsXMLList : XMLList;
- private var jietuXMLList : XMLList;
- //private var jietuArr : Array = [];
- //private var yuanhuaArr : Array = [];
- private var yuanhuaXMLList : XMLList;
- public var input : TextField;
- public function Data()
- {
- }
- public function start(url : String ="data/config.xml" ) : void
- {
- LoaderMax.activate([ImageLoader]);
- dataLoader = new XMLLoader(url, {onComplete:onDataInit});
- dataLoader.load();
- }
- private function onDataInit(event : LoaderEvent) : void
- {
- var data : XML = dataLoader.content as XML;
- p_w_picpathsXMLList = data.child("p_w_picpaths").children();
- for (var i : int = 0; i < p_w_picpathsXMLList.length(); i++)
- {
- p_w_picpathObj[p_w_picpathsXMLList[i].@url] = [p_w_picpathsXMLList[i].@http0,p_w_picpathsXMLList[i].@http1,p_w_picpathsXMLList[i].@http2,p_w_picpathsXMLList[i].@http3];
- p_w_picpathUrlArr.push(p_w_picpathsXMLList[i].@url)
- }
- jietuXMLList = data.child("jietu").children();
- yuanhuaXMLList = data.child("yuanhua").children();
- loadImages();
- }
- private function loadImages() : void
- {
- var queue : LoaderMax = new LoaderMax({onComplete:completeHandler,onProgress:progressHandler});
- for(var i : int = 0;i < p_w_picpathsXMLList.length();i++)
- queue.append(new ImageLoader(p_w_picpathsXMLList[i].@url, { container:null, name:p_w_picpathsXMLList[i].@url, smoothing:true } ));
- for(var j : int = 0;j < jietuXMLList.length();j++)
- queue.append(new ImageLoader(jietuXMLList[j].@url, { container:null, name:jietuXMLList[j].@url, smoothing:true } ));
- for(var k : int = 0;k < yuanhuaXMLList.length();k++)
- queue.append(new ImageLoader(yuanhuaXMLList[k].@url, { container:null, name:yuanhuaXMLList[k].@url, smoothing:true}));
- queue.load();
- }
- private function completeHandler(event : LoaderEvent) : void
- {
- for (var i:int = 0; i < p_w_picpathUrlArr.length;i++ )
- p_w_picpathArr.push(LoaderMax.getContent(p_w_picpathUrlArr[i]));
- for (var j:int = 0; j < jietuXMLList.length();j++ )
- BananerStaic.jietuArr.push(LoaderMax.getContent( jietuXMLList[j].@url));
- for (var k:int = 0; k < yuanhuaXMLList.length();k++ )
- BananerStaic.yuanhuaArr.push(LoaderMax.getContent(yuanhuaXMLList[k].@url));
- BananerStaic._bitmapArr = p_w_picpathArr;
- BananerStaic.p_w_picpathArr = p_w_picpathArr;
- this.dispatchEvent(new Event(Event.COMPLETE));
- }
- /**得到模型地址*/
- public static function getImageHttp(url : String) : * {
- if(p_w_picpathObj[url] == null || p_w_picpathObj[url] == undefined) {
- trace("没有这个........." + url);
- }
- return p_w_picpathObj[url];
- }
- /*** 进度 */
- //private var myProgressBar : Sprite = new Sprite();
- private function progressHandler(event : LoaderEvent) : void
- {
- input.text = Math.floor(event.target.progress * 100) + "%";
- //this.addChild(myProgressBar);
- //myProgressBar.graphics.beginFill(0xFF0000);
- //myProgressBar.graphics.drawRect(0, 0, event.target.progress * 100, 50);
- //trace(event.target.progress);
- //myProgressBar.scaleX = event.target.progress;
- }
- //end
- }
- }