4 Replies Latest reply on May 21, 2010 5:30 AM by Manystems-Arjen

    Spark textarea in ItemRenderer

    Manystems-Arjen Level 1

      I have a problem with text input or text area's in a ItemRenderer.

      I've created an simple ItemRenderer with two textarea's.

      In the creation complete of the ItemRenderer I set the text of the area to an variabele of the data oject of the item renderer.

       

      Like so:

      chatText.text = this.data.message; (i know for sure that the message string contains text at this point).

       

      When i use this ItemRenderer in a list it will show rows in the list but the textarea's do not contain any text.

      But when i click on the textarea in one row the text becomes vissible somehow.

       

      This only happens when is use the spark textarea, the mx textarea shows the text right away.

       

      Am i missing a setting or so which is new in flex 4?

        • 1. Re: Spark textarea in ItemRenderer
          TeotiGraphix Level 3

          Hi,

           

          Sounds like a layout issue, can you post the code to your itemRenderer?

           

          Mike

          • 2. Re: Spark textarea in ItemRenderer
            Manystems-Arjen Level 1

            Yep here's the code:

             

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                xmlns:s="library://ns.adobe.com/flex/spark" 
                                xmlns:mx="library://ns.adobe.com/flex/mx" 
                                creationComplete="itemrenderer1_creationCompleteHandler(event)"
                                autoDrawBackground="false"
                                >
                 <fx:Script>
                      <![CDATA[               
                           import mx.events.FlexEvent;          
                           protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
                           {
                                payload = this.data as ChatMessage;
                                
                                chatText.text = this.data.message;
                                userText.text = this.data.user.name;
                                dateText.text = this.data.date;                    
                           }
                      ]]>
                 </fx:Script>
                 <s:HGroup width="100%">          
                      <s:TextInput id="userText" editable="false" borderVisible="false"  width="10%"/>
                      <s:TextArea id="chatText" editable="false" borderVisible="false"  width="80%"  />
                      <s:TextInput id="dateText" editable="false" borderVisible="false"  width="10%"/>
                 </s:HGroup>
                 
            </s:ItemRenderer>
            
            • 3. Re: Spark textarea in ItemRenderer
              TeotiGraphix Level 3

              Well, looks to me like it's a timing issue, you need to adjust data when the data arrives.

               

              Try;

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                              xmlns:s="library://ns.adobe.com/flex/spark" 
                              xmlns:mx="library://ns.adobe.com/flex/mx" 
                              autoDrawBackground="false"
                              >
                  <fx:Script>
                      <![CDATA[
                          
                          private var payload:ChatMessage;
                          
                          override public function set data(value:Object):void
                          {
                              super.data = value;
                              
                              payload = data as ChatMessage;
                              
                              if (!payload)
                                  return;
                              
                              chatText.text = payload.message;
                              userText.text = payload.user.name;
                              dateText.text = payload.date;
                          }
                      ]]>
                  </fx:Script>
                  <s:HGroup width="100%">          
                      <s:TextInput id="userText" editable="false" borderVisible="false"  width="10%"/>
                      <s:TextArea id="chatText" editable="false" borderVisible="false"  width="80%"  />
                      <s:TextInput id="dateText" editable="false" borderVisible="false"  width="10%"/>
                  </s:HGroup>
                  
              </s:ItemRenderer>

               

              Mike

               

              PS If you get a null pointer reply back, you might need invalidation. I can't remeber if the new item renderers have their children created before or after data is set.

              • 4. Re: Spark textarea in ItemRenderer
                Manystems-Arjen Level 1

                Super, this works.

                Thanks a lot.