0 Replies Latest reply on Oct 8, 2007 10:17 AM by DJ_James

    Loading images from an Array generated from XML

      OK, this is my first day trying to use AS3 and I'm kind of confused on how to load an image onto the screen and then be able to resize it, scale it, etc..

      I'm loading up to 5 images in from an XML file that will be generated on a server. (right now I'm just using a test.xml file).

      Normally I would load the images into dynamically created movie clips (whatever0_mc through whatever4_mc generated by code in AS2). But I can't seem to get anything working.. I've looked on the internet and read through some information but I'm still just REALLY confused... this is what I have so far. To make it easier on me in the future, I've put different code on different layers so I can look at it closer.. I've separated the code into the different layers they're on here:

      First Layer:
      import flash.events.Event;
      import flash.net.URLLoader; // URL Loader Import for Images
      import flash.net.URLRequest; // URL Requests Import for Images
      import flash.display.Loader; // Loader
      import flash.events.ProgressEvent; // Progress for Loader
      import flash.text.TextField; // Imports for Text Fields
      import flash.display.Sprite; // Imports Sprite stuff for loaded Images
      import flash.display.Bitmap; // Imports stuff to display a bitmap

      Second Layer:
      var imgLoader:Loader = new Loader(); // Initialize Image Loader

      // Listeners for the Image Loaders //
      function showPreloader(evt:Event):void {
      trace("-- ** showPreloader ** --");

      function showProgress(evt:ProgressEvent):void {
      trace("-- ** showProgress ** --");
      var totalLoaded:Number = evt.bytesTotal;
      var currentLoaded:Number = evt.bytesLoaded;
      var thePercent:Number = (currentLoaded * 100) / totalLoaded;

      loadProgress_txt.text = thePercent + "%"; // Show bytes loaded

      function showLoadResult(evt:Event):void {
      trace("-- ** showLoadResult ** --");


      Third Layer:
      // Setup Variables //
      var imageArray:Array = new Array();
      var galleryTitle:String;
      var numPhotos:Number;
      var gallerySubmitter:String;

      // XML Info //
      XML.ignoreComments = true;
      XML.ignoreWhitespace = true;
      var galleryXML:XML;
      var xmlLoader:URLLoader = new URLLoader();
      var request:URLRequest = new URLRequest("test.xml");
      xmlLoader.addEventListener(Event.COMPLETE, XMLComplete);

      function XMLComplete(evt:Event):void {
      trace("-- ** XMLComplete ** --");
      var loader:URLLoader = evt.target as URLLoader;

      if (loader != null){
      galleryXML = new XML(loader.data);

      galleryTitle = galleryXML.children()[0].attributes()[0];
      numPhotos = galleryXML.children()[0].attributes()[1];
      gallerySubmitter = galleryXML.children()[0].attributes()[2];

      trace("galleryTitle: " + galleryTitle);
      trace("numPhotos: " + numPhotos);
      trace("gallerySubmitter: " + gallerySubmitter);

      for(var i:Number = 0; i<numPhotos; i++) {
      imageArray.push(galleryXML.children()[0].children() .attributes()[1]);

      } // for(var i:Number = 0; i<numPhotos; i++)

      trace("loading: images\\gallery\\" + imageArray[0]);

      var imgRequest:URLRequest = new URLRequest("images\\gallery\\" + imageArray[0]); // Request the Image into the Loader


      } else { // if (loader != null){
      trace("loader is not a URLLoader!");

      } // if (loader != null){

      } // function onComplete(event:Event):void {
      // End XML Info //

      Can anyone point me in the next direction? thanks...