1 Reply Latest reply on Oct 27, 2009 2:28 PM by sir humus

    displaying images from xml

    sir humus



      I have this xml file that contains urls for png files.

      I create a class that have a bitmap var

      and than i create instances of this class for each image.

      the constractor of this class gets string (the url) and try to load the image to the bitmap var.


      than I want to display all the image in a raw (inside canvas)


      the problems:

      1. it's seems that the loader never get the image file...

      2. even when I manually load the images, it always diplay only one image...


      what am I doing wrong?

        • 1. the code
          sir humus Level 1

          I guess it may help:


          the xml is like:












          the imges looks like: C3.png, C5.png, ...


          the card class:


          public class Card extends Sprite


          private var _suit:String;

          private var _rank:String;

          private var _image:Bitmap;

          private var loader:Loader;

          public function Card(suit:String, rank:String)


          _suit = suit;

          _rank = rank;

          loader = new Loader();

          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

          loader.load(new URLRequest(_suit + _rank + ".png"));


          private function imageLoaded(event:Event):void


          _image = new Bitmap(event.target.content.bitmapData);





          and the mxml have:

          private function dataHandler(event:DataEvent):void {

                  var xmlResp:XML = XML(event.data);

                     for each(var card:XML in xmlResp..Card){

                      var cardSuit:String = card.suit.toString();

              var cardRank:String = card.rank.toString();

               var tempCard:Card = new Card(cardSuit,cardRank);


          <mx:Canvas id="canvas0" width="400" height="148" horizontalCenter="0" verticalCenter="232"/>