来自:xihayouyi > flex
配色: 字号:
flex读取字节码生成图片
2012-05-24 | 阅:  转:  |  分享 
  
flex读取字节码生成图片
2010-01-26 22:50
  1. <mx:Script>   
  2.          <![CDATA[   
  3.              import mx.controls.Alert;   
  4.              import mx.core.UIComponent;   
  5.              import mx.utils.Base64Decoder;   
  6.              import mx.controls.Label;   
  7.              import mx.utils.Base64Encoder;   
  8.              var loader:Loader=new Loader;   
  9.              var baseEn:Base64Encoder=new Base64Encoder;//编码   
  10.              //编码   
  11.              private function init():void{   
  12.                  loader.load(new URLRequest("images/mah/1.png"));   
  13.                  loader.contentLoaderInfo.addEventListener(Event.COMPLETE,oncomplete);   
  14.              }   
  15.              private var strs:String   
  16.              private function oncomplete(e:Event){   
  17.                  baseEn.encodeBytes(e.target.bytes,0,e.target.bytes.length);   
  18.                  //Debug.log(baseEn.toString());   
  19.                  strs=baseEn.toString();   
  20.                  init2();   
  21.              }   
  22.              //解码   
  23.              var loader2:Loader=new Loader;   
  24.              var baseD:Base64Decoder=new Base64Decoder;   
  25.              public function init2():void{   
  26.                  baseD.decode(strs.toString());   
  27.                    
  28.                  loader2.loadBytes(baseD.toByteArray());   
  29.                  loader2.contentLoaderInfo.addEventListener(Event.COMPLETE,oncom);   
  30. //               var sp:Sprite=new Sprite;   
  31. //               sp.addChild(loader2);   
  32. //               var ui:UIComponent=new UIComponent;   
  33. //               ui.addChild(sp);   
  34. //               this.addChild(ui);   
  35.              }   
  36.                
  37.              private function oncom(e:Event){   
  38.                    
  39.                  var sp:Sprite=new Sprite;   
  40.                  sp.addChild(e.target.loader.content);   
  41.                  var ui:UIComponent=new UIComponent;   
  42.                  ui.addChild(sp);   
  43.                  this.addChild(ui);   
  44.              }   
  45.          ]]>   
  46.      </mx:Script>  

献花(0)
+1
(本文系xihayouyi首藏)
发表评论: