0

I made this class, which is an ItemRenderer class, used in a DataGroup ( mobile application ), and I am not entirely sure if I did the right thing or not, my issues are :

  1. Is there a better way to show the image, which is 80x80 and directly loaded from the server;
  2. How to make the height of the row dynamic, I mean, depending on the height of the 3 StyleableTextFeild
  3. Is this the right way to add the listener on the image, that will trigger a simple HTTPService,

Here is the functions from the class, Any help would be much appreciated !!

  • Image

Declared it as a simple image :

    var logo:Image;

On override createChildren

    logo = new Image();
    addChild(logo);

And I added on set Data

    logo.source = "http://192.168.0.15:3000/"+value.logo_thumb_url;
  • Size

    override protected function measure():void {
        measuredWidth = measuredMinWidth = stage.fullScreenWidth;
        measuredHeight = measuredMinHeight = 100;
    }
    
  • Listener

        override public function set data(value:Object):void {
        tel.text = String(value.Tel);
        description.text = String(value.Descricao);
        nome.text = String(value.Nome);
        logo.addEventListener(MouseEvent.CLICK, function():void{
                var service:HTTPService = new HTTPService();
                service.url = value.targer;
                service.method = "GET";
                // setting headers and other variables ...
                service.send();
            });
    }
    
Khalil Bhm
  • 394
  • 3
  • 13

1 Answers1

1
  1. You can use URLLoader or Loader for loading the image if you are planning to cache the image on the client side, if you cache the image, it wil help you not load the image again when the users scrolls through the list. (What you have done is Ok, but you will hit performance issues)
  2. For variable row height, if Datagroup does not work, use List. find it here Flex 4: Setting Spark List height to its content height
  3. There should be a buttonMode property for some items, make it buttonMode for the logo, for variable row height, find something related to wordWrap and variableRowHeight properties on the datagroup.

There are a few suggestions, what you have coded is good, but, instead of adding the listeners on set data, add it in creation complete, as it is more appropriate. Also, the event listeners has to be weak referenced, http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html#addEventListener()

Community
  • 1
  • 1
Zeus
  • 6,386
  • 6
  • 54
  • 89
  • I am sorry, even when I read the first question I didnt get what I wrote, I changed the code check it now – Khalil Bhm Oct 11 '13 at 20:21
  • Made modifications in the answer. – Zeus Oct 14 '13 at 17:55
  • And this is what I needed to know, Thank you ! about the listener, I did this because the link of the image will be inside the object Value ... and I am overriding these functions and don't really know how to access Value from anywhere else beside set data – Khalil Bhm Oct 14 '13 at 18:14
  • 1
    In the set data() method you can call super.data = value, and you can access the data by this.data property anywhere in the renderer – Zeus Oct 14 '13 at 18:19
  • Just a question, when I click on an element from the list, and made the listener your way, how am I able to know the link is from which object exactly ? – Khalil Bhm Oct 14 '13 at 20:26
  • You may be confused, step by step: 1. You add event listener to the itemrenderer on creationcomplete. 2. on set data() in first line call super.data = value(Doing this will help the whole itemrenderer know what the data is) 3. when some one clicks the image/link, you handle the event in the itemrenderer itself, since we set the super.data to some value, now you can get the value any where in the renderer by calling this.data – Zeus Oct 14 '13 at 20:56