4 Replies Latest reply on Mar 13, 2009 4:15 AM by Sankar Kethineni

    ItemRenderer in ActionScript

    Sankar Kethineni
      Hi All,

      am trying to build item renderer for a List component in action script rather than in mxml. In the action script class am creating a HBox dynamically and adding Labels to is by overriding the createChildern() and also overriding the updateDisplayList() and commitProperties() and in which am setting the values to labels.

      When i run the application in debug mode am able to see the values being set to the labels but am not seeing the values getting displayed in the List control.

      Here am posting the code,so that the problem can be identified.

      Can anyone help me how to resolve this problem?
        • 1. Re: ItemRenderer in ActionScript
          Level 7

          "sankar83" <webforumsuser@macromedia.com> wrote in message
          news:gp7ejg$3ur$1@forums.macromedia.com...
          > Hi All,
          >
          > am trying to build item renderer for a List component in action script
          > rather
          > than in mxml. In the action script class am creating a HBox dynamically
          > and
          > adding Labels to is by overriding the createChildern() and also overriding
          > the
          > updateDisplayList() and commitProperties() and in which am setting the
          > values
          > to labels.

          Try just extending HBox, rather than UIComponent. An HBox in a UIComponent
          is even slower and heavier than just an HBox. This will also solve your
          problem, because HBox automatically sizes and lays out its children.

          HTH;

          Amy


          • 2. Re: ItemRenderer in ActionScript
            Sankar Kethineni Level 1
            Hi All,

            Myself got the solution for this problem.The only change in the code is, i forget to add the HBox container to the display object at the end of createChildern() as shown here

            override protected function createChildren():void {
            super.createChildren();

            hBox = new HBox();
            ..............
            this.addChild(hBox);
            }

            It works fine, if the data(ArrayCollection) is static but it doesn't work if the data is dynamic i.e if you try to get the data from the database and am getting the runtime error as shown below

            Cannot access a property or method of a null object reference

            at the line where we were setting the values to the labels in the commitProprties() method.Since we all know that, child component elements(controls) will be created and initialized first and then parent components will be created and initialized.In my parent component am firing the creationComplete event to get the data from the Database and it will be fired after the child components has been created and initialized.

            In this case, first item renderer written in action script will be executed and in that we were trying to set the values to labels and the data property not available by that time and then creationComplete event of it's parent component gets fired and now we will have the data from the database.I think from 2nd time onwards data property will be available.

            How do i solve this problem? I think itemrenderer should be executed only when the data from the database gets bounded to arrayCollection object.Is it correct?

            Please, Can anyone help me ?

            Thanks
            sankar


            • 3. Re: ItemRenderer in ActionScript
              Level 7

              "sankar83" <webforumsuser@macromedia.com> wrote in message
              news:gpae12$pdl$1@forums.macromedia.com...
              > Hi All,
              >
              > Myself got the solution for this problem.The only change
              > in
              > the code is, i forget to add the HBox container to the display object at
              > the
              > end of createChildern() as shown here
              >
              > override protected function createChildren():void {
              > super.createChildren();
              >
              > hBox = new HBox();
              > ..............
              > this.addChild(hBox);
              > }
              >
              > It works fine, if the
              > data(ArrayCollection) is static but it doesn't work if the data is dynamic
              > i.e
              > if you try to get the data from the database and am getting the runtime
              > error
              > as shown below
              >
              > Cannot access a property or method of a null object
              > reference

              >
              > at the line where we were setting the values to the labels in the
              > commitProprties() method.Since we all know that, child component
              > elements(controls) will be created and initialized first and then parent
              > components will be created and initialized.In my parent component am
              > firing the
              > creationComplete event to get the data from the Database and it will be
              > fired
              > after the child components has been created and initialized.
              >
              > In this case, first item renderer written in action
              > script will be executed and in that we were trying to set the values to
              > labels
              > and the data property not available by that time and then creationComplete
              > event of it's parent component gets fired and now we will have the data
              > from
              > the database.I think from 2nd time onwards data property will be
              > available.
              >
              > How do i solve this problem? I think itemrenderer should be executed only
              > when the data from the database gets bounded to arrayCollection object.Is
              > it
              > correct?

              Set a flag in your data setter if data is not null and use that to determine
              if you should set your label.


              • 4. Re: ItemRenderer in ActionScript
                Sankar Kethineni Level 1
                Hi,

                I tried as Amy Blankenship told and it work's for me.

                Thanks for your help
                -sankar