4 Replies Latest reply on Jul 17, 2006 2:35 PM by Jinglesthula

    Image control runtime creation issue

      I am having problems getting the Image control to actually display the image I specify in the source property. The Image control is created in actionscript at runtime based on XML returned by an HTTPService request. I have a canvas that I want to populate with Label, Text, Image, LinkButton, etc. controls based on the contents of the XML file that is read in, so I have to create all the components on the fly and use something like this:

      var newImage:Image = new Image();
      newImage.setStyle("source", "images/myImageFile.jpg");

      After I get all the newly created components added as children to the canvas I go back through and do positioning (something like this):

      for each (var child:DisplayObject in myCanvas.getChildren()) {
      //set the y property of each component to the y of the previous child plus
      //the height of the previous child plus 10 px margin

      Wherever there is an image in my XML it inserts the 10px margin for that component, so I know it's creating it and that it gets added as a child, but for some reason the image is not displaying and so the height of the component is 0. I even tried hardcoding the height of each Image control in case the image was there but it just wasn't sizing right, but it puts in the space without displaying the image.

      What I'm wondering is if there is some method that will force the Image controls to either load the image or render it. When I add an Image in mxml and use the exact same source data it displays just fine, so the file path is correct. I also have the same images being read in from XML off the HTTPService that are showing up just fine in a TileList where my itemRenderer component has an image with the source set to the same path as I'm trying to use in the runtime-generated Image controls.

      Also, as a side question, does anyone know why a lot of the properties/methods available from mxml specified comonents aren't available when you create variables of the same type in actionscript? For example, if I have
      <mx:Image id"img"/>
      I can go back in actionscript and reference img.source just fine. On the other hand, if I declare an Image in actionscript, thus:
      private var asImg:Image = new Image();

      and then try to refer to the source property like so:


      it doesn't show up in the code hinting and it also throws an error on compile (reference to a possibly undefined property source for bla bla bla)

      Actually, I've noticed that a lot of the properties and methods of various components aren't available when they are actionscript rather than mxml. I didn't see much in the documentation on the difference or what could be done to work around it.

      Thanks much anyone who has input.