0 Replies Latest reply on Jan 26, 2012 2:37 PM by Luis Pedro Ferreira

    Custom and conditional LabelItemRender (sectioned lists)

    Luis Pedro Ferreira Level 1

      HI all.

       

      I will start with a questions:

      How do I create a list with sections like a phonebook list??

       

      Ok, I know there a several places where I can read about this, and the best option I read was to create a custom ItemRender with some conditions from the data passed.

       

      So far so good, I have a data.type which tells my custom ItemRender that it should behave as a row or a header ... makes sence but !! ... I'm always getting runtime errors regarding some undifined or something null.

      So I guess is something related to lifecycle of the ItemRender. Something that is being called that is not created yet, but what??

       

      So let's say, for example that on my custom ItemRender I have:

       

                          private var itemType:String;

                          private var headLabel:StyleableTextField;

                          private var routeLable:StyleableTextField;

       

                          override public function set data(value:Object):void

                          {

                                    super.data = value;

        // the data has changed.  push these changes down in to the

        // subcomponents here

       

                                    if(data.type == "header"){

                                              itemType = data.type;

                                              headLabel.text = data.dateLabel;

        //this.height = 20;

                                    } else{

                                              itemType = null;

                                              routeLable.text = data.route;

                                    }

                          }

       

                          override protected function createChildren():void

                          {

                                    super.createChildren();

        // create any additional children for your item renderer here

        if(!itemType){ // When I use the condition, is when I get those runtime errors.

                                              routeLable = StyleableTextField(createInFontContext(StyleableTextField));

                                              routeLable.styleName = this;

                                              routeLable.styleDeclaration = styleManager.getStyleDeclaration(".routeLable");

                                              routeLable.editable = false;

                                              routeLable.selectable = false;

                                              routeLable.multiline = false;

                                              routeLable.wordWrap = false;

                                              routeLable.cacheAsBitmap = true;

                                              addChild(routeLable);

      } else {

                                              headLabel = StyleableTextField(createInFontContext(StyleableTextField));

                                              headLabel.styleName = this;

                                              headLabel.styleDeclaration = styleManager.getStyleDeclaration(".timesLable");

                                              headLabel.editable = false;

                                              headLabel.selectable = false;

                                              headLabel.multiline = false;

                                              headLabel.wordWrap = false;

                                              headLabel.cacheAsBitmap = true;

                                              addChild(headLabel);

      }

                          }

       

      Why am I getting runtime errors with null reference??

       

      Does anyone have an solution to do lists with sections??

      There's also another questions: How do I set the itemRender not selectable if is an "header"?

       

      Hope you can hep me.

       

      LP