Image control runtime creation issue

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default 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");
    myCanvas.addChild(newImage);

    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:

    asImg.source

    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.

    Jinglesthula Guest

  2. Similar Questions and Discussions

    1. Web user control creation - Resolve an ImageUrl property if control themed
      Hi I'm creating a WebControl which has a themeable ImageUrl property : <Bindable(True), Category("Appearance"),...
    2. Creation and Positioning DataGrid Columns at runtime.
      Hello, I need to create a DataGrid that looks something like this... <HyperLinkColumn><ButtonColumn><Data><Data><ButtonColumn> but I can only...
    3. Adding Validator Control at runtime in a Custom Control
      Hi Wim, How do we link the TextBox to this validator control class in runtime ? Could you please tell. Thanks _ Muds. Wim Hollebrandse...
    4. ASP.NET DataGrid and TextBox creation at runtime?
      Hello, How do I create the following at runtime? I am able to create a TextBox Column at runtime using "DataGridColumn" class. But I don't know...
    5. Runtime control creation
      I'm building a page in which - at runtime - I'm adding Button controls to an asp:tablecell. Code looks more or less like this : Public Sub...
  3. #2

    Default Re: Image control runtime creation issue

    Anybody? .... Bueller? ....
    Jinglesthula Guest

  4. #3

    Default Re: Image control runtime creation issue

    Have you tried embedding the image asset? This stuff is well outside my areas of expertise, but, hey, I'm trying.

    Tracy
    ntsiii Guest

  5. #4

    Default Re: Image control runtime creation issue

    The problem is that I want the images to be specified at runtime based on the
    contents of the XML file which may change without the Flex app ever being
    recompiled. I've embedded images in other Flex apps before, but that requires
    that all embedded images to be available at compile time. Thanks for the
    suggestion, though. I appreciate it.

    Jon

    Jinglesthula Guest

  6. #5

    Default Re: Image control runtime creation issue

    Ok, got it.

    I figured that since the <mx:Image> renders just fine and that the
    ActionScript Image object doesn't that I'd just create a custom mxml component
    with Image as the base element and with nothing else in it. Then I add an
    instance of my custom image component in AS whenever the XML specifies one.
    The layout was a bit of an issue, but I just added the image dimensions as
    attributes in my XML and size the CustomImage component based on those.

    Must be some subtle difference between the mxml and AS Image classes that
    isn't documented very well.

    Jinglesthula Guest

  7. #6

    Default Re: Image control runtime creation issue

    if you are running it on server, try movinf images to theweb content folder and specify the path of images as http://<server>:<port>/<projectname>/<floder>/image.jpeg
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139