2 Replies Latest reply on Oct 1, 2008 2:09 AM by genek07

    Convert Image to Class - or load images into a TileList dynamically

      I'm trying to load images dynamically into a TileList. The problem seems to be that the TileList's iconFunction must return a Class. So this (which is what all the examples I can find on this topic do) will work:

      var myTestImage:Class;

      function myReturnIcon ( row:Object ):Class {
      return myTestImage;

      But it obviously returns the same image all the time, plus it embedded into the application. I need to load the images dynamically. If I write this:

      function myReturnIcon ( row:Object ):Image {
      var i : Image = new Image();
      i.load( row.imagepath );
      return i;

      it loads the images, but throws this error: Type Coercion failed: cannot convert mx.controls::Image@16d4ecf1 to Class. This makes sense too, since I know we need a Class and not an Image... but what I don't know is, how to load an image from a URL and then turn it into a class, or return it as class.

      Any help with this would be greatly appreciated.
        • 1. Re: Convert Image to Class - or load images into a TileList dynamically
          The tileList is a very tricky control. I`m sitting for quite a while to make it more accessible. By the way I think i`ve managed the dynamically loading of images:
          1.You need an xml-File, which contains your tagged images.
          2.You have to use an item-Renderer in your main-mxml-Application
          3.You load the pics dynamically via an HTTPService, you will also need a DataProvider (You don`t need a class file unless you want to have the user manipulate your pictures[In my example below I needed to randomize the sorting, so i had to use a class]
          4. In the Item-renderer the images are loaded as follows:
          <mx:Image source="assets/{data.image}"..where data.image points to e4x formatted return result of the ArrayCollection-Provider (the xml file with the name of your pics in an <image/> tag.
          Check out this application (Rightclick-View Source) then i think you`ll understand the logic:

          Greetings, moccamedium
          • 2. Re: Convert Image to Class - or load images into a TileList dynamically
            Hi, moccamedium.

            It is necessary to make, so that icons for tree nodes, were loaded dynamically.
            And convert Image to Class to use (item:Object, iconID:Class, iconID2:Class) method

            It would be desirable to look a working example, the link does not work.