URLLoader 导入二进制

 

package  
...
    
import com.wdxc.ImageCut;
    
import flash.geom.Point;
    
import flash.geom.Rectangle;
    
import flash.net.URLLoader;
    
import flash.net.URLRequest;
    
import flash.events.* ;
    
import flash.display.*;
    
import flash.geom.* ;
    
import flash.net.*;
    
import flash.text.TextField;
    
import flash.utils.ByteArray;
    
import com.wdxc.util.* ;      
    
    
/** *//**  
     * 
@author luqinglong
     
*/
 
    
public class Main extends MovieClip
    
...{
        
//存储加载进来的图片数据
        private var _bitmap:Bitmap = new Bitmap() ;                  
        
//进度条
        private var _progressbar:TextField ;
        
        
private var picname:String ; 
           
        
private var _imageCut:ImageCut = new ImageCut() ;
               
        
//场景引用
        public static var SCENE:MovieClip ;
          
        
public function Main():void ...{      
            SCENE 
= this;          
            
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            
this.loaderInfo.addEventListener(Event.COMPLETE, fileCompleteHandler) ; 
        }
    
          
        
public function set bitmap(bp:Bitmap):void ...{
            
this._bitmap = bp ;
        }
 
            
        
public function get bitmap():Bitmap ...{
            
return this._bitmap ;
        }

        
        
/** *//**
         * flash文件导入完成
         * 
@param    e
         
*/

        
private function fileCompleteHandler(e:Event):void ...{
            
this.removeChild(_progressbar);                  
            menu_mc.cut_btn.addEventListener(MouseEvent.MOUSE_DOWN, 
this._imageCut.startCutPic);
            menu_mc.save_btn.addEventListener(MouseEvent.MOUSE_DOWN, save) ;
            load_btn.addEventListener(MouseEvent.MOUSE_DOWN, loadPic);     
                 
            
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
            
this.loaderInfo.removeEventListener(Event.COMPLETE, fileCompleteHandler) ;       

        }

            
        
/** *//**  
         * 导入swf文件时,创建进度条
         
*/

        
private function progressHandler(e:ProgressEvent):void ...{
            _progressbar 
= new TextField() ;
            _progressbar.text 
= "进度条" ;        
            
this.addChild(_progressbar) ;     
        }
    
                         
         
        
public function loadPic(e:MouseEvent):void ...{   
            
//var picSource:String = "http://192.168.0.211/cut?"+Math.floor(Math.random()*1000); 
            var picSource:String = "F:\a.jpg" ;  
            var request:URLRequest 
= new URLRequest(picSource);
            var _urlLoader:URLLoader 
= new URLLoader(); 
            _urlLoader.dataFormat 
= URLLoaderDataFormat.BINARY ;
            _urlLoader.load(request);             
            _urlLoader.addEventListener(Event.COMPLETE, picLoadCompleteHandler);  
        }

           
        
/** *//**  
         * 导入二进制完成
         * 
@param    e
         
*/
   
        
private function picLoadCompleteHandler(e:Event):void ...{
            var 
byte:ByteArray = e.target.data as ByteArray;    
            var loader:Loader 
= new Loader();      
            loader.loadBytes(
byte);   
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ConvertionHandler) ;
            e.currentTarget.removeEventListener(Event.COMPLETE, picLoadCompleteHandler); 
        }
    
         
         
/** *//****     
         * 转换为字节数组,显示图片到场景
         * 
@param    e 
         
*/
    
        
private function ConvertionHandler(e:Event):void ...
            var loader:Loader 
= e.target.loader as Loader;   
            var _bitmapdata:BitmapData
= new BitmapData(loader.width, loader.height);
            _bitmapdata.draw(loader);
            
            
if(this._bitmap.bitmapData!=null)
                
this._bitmap.bitmapData.dispose() ; 
                      
            
this._bitmap.bitmapData = _bitmapdata;        
            _bitmap.x 
= 93  ;     
            _bitmap.y 
= 150 ;                        
            
this.addChild(_bitmap);  
             
            
//设置原图引用                 
            this._imageCut.bitmap = this._bitmap ;               
            
this.addChild(this._imageCut);
            e.currentTarget.removeEventListener(Event.COMPLETE, ConvertionHandler);           
        }

        
private function save(e:MouseEvent):void ...{
            
//var url :String = _url+"?"+Math.floor(Math.random()*1000) ;   
            
//this.submit(bitmapdata,url);   
        }

    }
   
}

 

你可能感兴趣的:(.net,F#,Flash)