5 Replies Latest reply on Apr 29, 2009 10:08 AM by jylaxx

    Adding String Please HELP!




      I need to know the formatting that action script uses to add strings to variables.


      For example I have this code


      public function addString(str1:String):void



           For (i:int =0; i<data.length; i++)


                trace (data[i].str1)





      obviously this doesnt work but what is the format to get the string to correctly attached itself to the end of data[i]. ??

        • 1. Re: Adding String Please HELP!
          Michael Borbor Level 4

          I don't know if this is what you want.


          private var myString:String="A random text."
                         public function init():void{
                              myString+=" at the end of the day."

          If it isn't  what you want try to clarify your issue a little bit.

          • 2. Re: Adding String Please HELP!
            RUSH-ME Level 3



















            What I understood from your query, this may help you.




            function itemToString(item:Object, str:String):Void



















            trace( item[str]);









            Can you make more clarification about your quer please.

            • 3. Re: Adding String Please HELP!
              MrFork Level 1

              Thanks for the reply but its not what I mean.


              I'll try to explain what I mean. I want to be able to loop around an array (data array in the example) but use a string to extact the data fromthe array.


              So for example: this would work.


              Data Array

              Sales Value    Sales Volume 

              200                    458

              300                    451   

              200                    587

              100                    145



              public function addString():void



                   For (i:int =0; i<data.length; i++)


                        trace (data[i].salesValue);





              Output: 200, 300, 200, 100.



              but what I want to be able to do is to 'feed in' the field to the function and use that to extract the data from the array.


              str1 = "Sales Volume"




              public function addString(str1:String:):void



                   For (i:int =0; i<data.length; i++)


                        trace (data[i].{str1}); <---something like this?---->





              Output 458 451 587 145

              • 4. Re: Adding String Please HELP!
                run,ryan! Level 3

                for loop the array

                var destStr1:string = '';
                var dest2:string = '';
                for(var arr_key:string in yourArray)
                     destStr1 += arr_key + ','; //this is a string formed by keys of array
                     dest2 += yourArray[arr_key] + ','; //this is a string formed by values of array
                //you need some extra code to eliminate the seperator in the end of the string
                • 5. Re: Adding String Please HELP!
                  jylaxx Level 1
                  trace (data[i].{str1}); <---something like this?---->

                  To get a property value defined by a string variable write :


                  data[i] is an object of your collection and data[i][str1] is the "str1" property of this object.