Question

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();
            });
    }
    
Était-ce utile?

La solution

  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()

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top