8 Replies Latest reply on Feb 20, 2011 9:57 AM by miguel8312

    {data.test) to string in customitemrenderer

    jdrx

      Hi there,

       

      I am new to flex and have a simple question.

       

      I populated a advanced datagrid with an external xml file and use customintemrenderers.

       

      Within the customitemrendere I display the data with a label:

       

          <s:BorderContainer x="500" y="0" width="50" height="90" borderVisible="false" backgroundColor="#cccccc">
              <s:Label id="lblData_test" text="{data.test}"  width="50" height="90" y="0" x="0"/>
          </s:BorderContainer>

       

      All works well.

       

      But I need just a part of {data.test}

       

      For instance in the xml data.test is as follows

       

      <test>word_one word_two word_three</test>

       

      So how can I assign {data.test} to a string and work on the string, and eventually display the string in the label

       

          <s:BorderContainer x="500" y="0" width="50" height="90" borderVisible="false" backgroundColor="#cccccc">
               <s:Label id="lblData_test" text="{string}"  width="50" height="90" y="0" x="0"/>
           </s:BorderContainer>

       

      Or is there another way to do this.

       

      Thanx

        • 1. Re: {data.test) to string in customitemrenderer
          miguel8312 Level 3

          you have to make the string var bindable.

          so something like this should worl

          [Bindable]
          public var myString:String;
          


          then somewhere in your source code you have to

          myString = data.test 

           

          or another way you can acomplish this is when using e4x and parsing the xml you can use the substr function to jus grab the part of the xml that you want and assign it to a string variable.  Just a couple of ideas that come to mind.

          Miguel

          • 2. Re: {data.test) to string in customitemrenderer
            jdrx Level 1

            Hi Miguel,

             

            Thanks for the info.

             

            It works as you suggested but when running I get a

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.

             

            After dismissing it runs like I wanted (exept I have to manipulate the data first)

            • 3. Re: {data.test) to string in customitemrenderer
              miguel8312 Level 3

              can i see the source code im not sure where your getting this error and where are you actually assigning the string the value.  Typically you get the error due to the value no longer being avaliable or its not within scope anymore.

               

               

               

              Miguel

               

               

              you may also try instatinating the class of string as such

               

               

              [Bindable]

              public var myString:String = new String();

               

              Message was edited by: miguel8312

              • 4. Re: {data.test) to string in customitemrenderer
                jdrx Level 1

                Hi again,

                 

                Before showing the code:

                 

                I actually had the string assigned in a function on a creationcomplete for the customitemrenderer. I understand from the reply that this is the wrong place.

                 

                I also tried the initialize on the custom itemrendere but that's to soon

                 

                Where in the proces should I execute the function?

                 

                main mxml shows the advanceddatagrid with a custom item renderer in separate file.

                 

                some pseudo code for the itemrenderer

                 

                <s:MXAdvancedDataGridItemRenderer .... >

                <s:states></s:states>  //two off them

                 

                script tags with the var creation, function for the var and changestate

                 

                And then a lot off bordercontainers with labels to show the data

                 

                IfThanx again.

                • 5. Re: {data.test) to string in customitemrenderer
                  miguel8312 Level 3

                  jdrx is your question answered now? or do you still need help im not sure from reading your last post buddy. Just let me know im willing to give you hand. I dont quite follow what your saying in the last post. Are you trying to manipulate the string after you added it to the datagrid or before adding it to the grid?

                  Miguel

                  • 6. Re: {data.test) to string in customitemrenderer
                    jdrx Level 1

                    Hi Miguel,

                     

                    Yes still need help :-(

                     

                     

                    I want to manipulate the string in the custom item renderer for the datagrid before it shows on screen

                     

                    I have two files:

                     

                    The first with the main datagrid  and the second with the customitemrenderer

                     

                    The XML is connected in the first file, showed with a datagrid trough the customitemrenderer in the second file.

                     

                    I like to manupulate {data.test) before it shows in the customitem renderer.

                     

                    Your tips helped me a lot but I still have the same errorcode (but it works fine nonetheless).

                     

                    So in the second file

                     

                    create the var

                    fill the var with data.test

                    manipulate the var

                     

                    show var in the label in the custom item renderer instead of data.test

                     

                    I have a little function to fill the var (and later on to manipulate).

                     

                    But I don't know when to execute the function to get rid of the error messages.

                     

                    initialize may be to soon, oncomplete to late. (for the whole custom renderer)

                     

                    So wich event should trigger the function is my main question

                     

                    Or should I try another route to manipulate the data.test

                     

                    Thanx agian, mucho appreciated!

                    • 7. Re: {data.test) to string in customitemrenderer
                      jdrx Level 1

                      Hi Miguel,

                       

                      I have it working, thanx for the support!

                      • 8. Re: {data.test) to string in customitemrenderer
                        miguel8312 Level 3

                        good to hear. sorry i didnt get back to you. I got lost in the work  shuffle.