[MultipartURLLoader] [서버에 파일 올리기] 간단 사용법



출처 : http://blog.inspirit.ru/

 
파일레퍼런스로 파일을 불러오고 서버에 올리는 간단한 코드를 보겠다.

 
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.FileReference;
    
    import multiPartURLLoader.MultipartURLLoader;
    
    public class MultiPartTest extends Sprite
    {
        private var ml : MultipartURLLoader;
        public function MultiPartTest()
        {
            ml = new MultipartURLLoader;
            ml.addEventListener(Event.COMPLETE , onComplete);
            
            stage.addEventListener(MouseEvent.CLICK , ck);
        }
        
        protected function ck(event:Event):void
        {
            trace("click!");
            // TODO Auto-generated method stub
                        
            var fr : FileReference = new FileReference();
            fr.browse();
            
            fr.addEventListener(Event.SELECT , select);
            fr.addEventListener(Event.COMPLETE , loadComplete);
            function select(e:Event):void
            {
                trace("select" , e.target is FileReference);
                fr.load();
            }
            function loadComplete(e:Event):void
            {
                trace("complete!" , fr.data.length);
                ml.addVariable('contentType', 'multipart/form-data');
                ml.addFile(fr.data , "TEST123.jpg" , "Filedata[]");
                var url:String = //serverURL//"
                ml.load(url);
            }
        }
        
        protected function onComplete(event:Event):void
        {
            trace("upload complete!");
            // TODO Auto-generated method stub
        }
    }
}

Yamecoder 야매코더_
C# 2011.05.19 15:31
Powerd by Tistory, designed by criuce
rss