How to load file for ActionScript 3

 

  import flashx.textLayout.elements.TextFlow;

   import flashx.textLayout.conversion.TextConverter;

   import flash.events.Event;
   import flash.events.IOErrorEvent;

Load file
  

   var loader:URLLoader = new URLLoader();
     loader.load(new URLRequest("../SimpleText.xml")); // for example
     loader.addEventListener(Event.COMPLETE,loadCompleteHandler);
     loader.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);

 /** on success parse the file and display it */

   private function loadCompleteHandler(e:Event):void
   {
     editor.textFlow = TextConverter.importToFlow(e.target.data, TextConverter.TEXT_LAYOUT_FORMAT);
   }

 

 private function errorHandler(e:IOErrorEvent):void
   {
    editor.textFlow = TextConverter.importToFlow("\n"+IOErrorEvent(e).text, TextConverter.PLAIN_TEXT_FORMAT);
   }
本篇發表於 作法 並標籤為 , 。將永久鏈結加入書籤。

發佈留言