Chapter 27 Example 7

by actionscriptbible
♥0 | Line 22 | Modified 2010-02-03 06:06:07 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iyHO
 */

package {
  import com.actionscriptbible.Example;
  import flash.events.Event;
  import flash.net.*;
  import flash.utils.ByteArray;
  
  public class ch27ex7 extends Example {
    public function ch27ex7() {
      var URL:String = "http://actionscriptbible.com/files/caviar.jpg";
      var loader:URLLoader = new URLLoader(new URLRequest(URL));
      loader.dataFormat = URLLoaderDataFormat.BINARY;
      loader.addEventListener(Event.COMPLETE, onLoadComplete);
    }
    protected function onLoadComplete(event:Event):void {
      trace("Done loading JPEG.");
      var loader:URLLoader = URLLoader(event.target);
      var data:ByteArray = ByteArray(loader.data);
      data.position = 0x06; //the JFIF id string starts 6 bytes into the file
      //the JFIF id is the zero-terminated string "JFIF" so if we try to 
      //read in a string starting here, we should find "JFIF".
      var markerString:String = data.readUTFBytes(4);
      trace("Marker: " + markerString);
    }
  }
}