加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flash笔记之URLStream和loader域载入swf

发布时间:2020-12-15 06:51:25 所属栏目:百科 来源:网络整理
导读:? private function loadPreAssets():void{ this.stream = new URLStream(); this.stream.addEventListener(Event.COMPLETE,this.onStreamHandler); this.stream.load(new URLRequest(SysConfig.path + SysConfig.toVersion(this.path))); } private functio
?
 private function loadPreAssets():void{
            this.stream = new URLStream();
            this.stream.addEventListener(Event.COMPLETE,this.onStreamHandler);
            this.stream.load(new URLRequest(SysConfig.path + SysConfig.toVersion(this.path)));
        }

 private function onStreamHandler(e:Event):void{
            this.stream.removeEventListener(Event.COMPLETE,this.onStreamHandler);
            var ba:ByteArray = new ByteArray();
            this.stream.readBytes(ba);
			
            var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoaderHandler);
			loader.loadBytes(ba,SysConfig.loaderContext);
            this.stream.close();
            this.dispatchEvent(new Event(Event.COMPLETE));
        }

private function onLoaderHandler(e:Event):void{
            e.target.removeEventListener(Event.COMPLETE,this.onLoaderHandler);
            this.toInitUi();
        }

private function toInitUi():void{
            var skin:Skin = new Skin(this.toGetUi("pre_bg"));
			skin.x = 0;
			skin.y = 0;
            this.bgBar.addChild(skin);
			
            var tformat:TextFormat = new TextFormat("宋体",12,0xDDDDDD);
            tformat.align = TextFormatAlign.CENTER;
			
			skin = new Skin(this.toGetUi("pre_bg_blue"),new Rectangle(40,7,150,5));
            skin.setSize((this.loadWid - 50),skin.height);
			skin.x = (this.loadWid - skin.width) * 0.5;
			skin.y = 20;
            this.loadBar.addChild(skin);
            
            this.curBar = new Skin(this.toGetUi("pre_bar_blue"));
            this.curBar.setSize(0,this.curBar.height);
			this.curBar.x = skin.x + 33;
			this.curBar.y = skin.y + 4;
            this.loadBar.addChild(this.curBar);
           
            this.lblCur = this.getTf(this.loadWid);
            this.lblCur.defaultTextFormat = tformat;
			this.lblCur.x = 0;
			this.lblCur.y = skin.y + 1;
            this.lblCur.text = " 0 %";
            this.loadBar.addChild(this.lblCur);
            
			skin = new Skin(this.toGetUi("pre_bg_yellow"),5));
			skin.setSize((this.loadWid - 50),skin.height);
			skin.x = (this.loadWid - skin.width) * 0.5;
			skin.y = 45;
			this.loadBar.addChild(skin);
			
            this.totalBar = new Skin(this.toGetUi("pre_bar_yellow"));
            this.totalBar.setSize(0,this.totalBar.height);
			this.totalBar.x = skin.x + 33;
			this.totalBar.y = skin.y + 5;
            this.loadBar.addChild(this.totalBar);
            
            this.lblTotal = this.getTf(this.loadWid);
            this.lblTotal.defaultTextFormat = tformat;
            this.lblTotal.text = " 0 %";
			this.lblTotal.x = 0;
			this.lblTotal.y = skin.y + 1;
            this.loadBar.addChild(this.lblTotal);
            
//            this.initHttpNet();
        }

 private function toGetUi(style:String):BitmapData{
            var c:Class = null;
            try {
                c = ApplicationDomain.currentDomain.getDefinition(style) as Class;
            } catch(e:Error) {
                return null;
            };
            var bmd:BitmapData = (new c(50,50) as BitmapData);
            return bmd;
        }

public function Skin(bmpData : BitmapData,scale9Grid:Rectangle=null)
		{
//			if(bmpData!=null)trace(bmpData.width+"___"+bmpData.height);
			if(scale9Grid){
				this.scaleBitmap = new ScaleBitmap(bmpData);
				this.scaleBitmap.scale9Grid = scale9Grid.clone();				
				this.bitmapData  = scaleBitmap.bitmapData;
			} else {
				this.bitmapData = bmpData; //.clone();  
			}
		}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读