flex读取字节码生成图片

<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.core.UIComponent;
			import mx.utils.Base64Decoder;
			import mx.controls.Label;
			import mx.utils.Base64Encoder;
			var loader:Loader=new Loader;
			var baseEn:Base64Encoder=new Base64Encoder;//编码
			//编码
			private function init():void{
				loader.load(new URLRequest("images/mah/1.png"));
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,oncomplete);
			}
			private var strs:String
			private function oncomplete(e:Event){
				baseEn.encodeBytes(e.target.bytes,0,e.target.bytes.length);
				//Debug.log(baseEn.toString());
				strs=baseEn.toString();
				init2();
			}
			//解码 
			var loader2:Loader=new Loader;
			var baseD:Base64Decoder=new Base64Decoder;
			public function init2():void{
				baseD.decode(strs.toString());
				
				loader2.loadBytes(baseD.toByteArray());
				loader2.contentLoaderInfo.addEventListener(Event.COMPLETE,oncom);
//				var sp:Sprite=new Sprite;
//				sp.addChild(loader2);
//				var ui:UIComponent=new UIComponent;
//				ui.addChild(sp);
//				this.addChild(ui);
			}
			
			private function oncom(e:Event){
				
				var sp:Sprite=new Sprite;
				sp.addChild(e.target.loader.content);
				var ui:UIComponent=new UIComponent;
				ui.addChild(sp);
				this.addChild(ui);
			}
		]]>
	</mx:Script>

 

你可能感兴趣的:(UI,Flex)