Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-22-2012, 09:06 PM   #1
kadin
Registered User
 
Join Date: Mar 2012
Posts: 29
Default convert array collection to string. The array has excess information.

This is a datagrid with two columns. I plan on having many columns. Each column input says add text here. When user clicks on that input,(add text here) gets replaced or updated with the user input. The columbs are editable, so if the user changes his mind the ArrayCollection gets updated.

I test this by inputing: sentence01 test. and sentence02 test. and click the button which converts the contents of the weatherInfo array object to a string that I can send to php.

The array is converted to a string and sent to php. PHP emails me the string and this is what I recieve:

nullD3315A22-768D-F239-D0D6-729798515A31, sentence01 test, F55EA87E-A1B9-B9DF-2EC1-7297993BDD51, sentence02 test,

When I use mx.controls.Alert.show("weather info="+ weatherInfo);. It says the same thing.

The weatherInfo array object has this (D3315A22-768D-F239-D0D6-729798515A31) additional information.

How do I get a string into php with just the input values (sentence01 test, sentence02 test,)? Thanks.

Code:
<s:HTTPService method="POST" resultFormat="e4x">
  <s:request xmlns="">
  <str>{str}</str>
</s:HTTPService>

[Bindable] private var weatherInfo:ArrayCollection = new ArrayCollection
                ([{tex01:'add text here'}, {tex02:'add text here'}]);

[Bindable] private var str:String;

private function buttonHandler(event:Event):void {
  str = arrayCollectionToString(weatherInfo);
}

public static function arrayCollectionToString( weatherInfo:ArrayCollection ):String 
  { 
     var collStr:String;
     for each( var obj:Object in weatherInfo ) 
        { 
           for each( var obj2:Object in obj ) 
               { 
                   collStr += obj2.toString() + ", "; 
               } 
        } 
      return collStr; 
  }

<mx:DataGrid dataProvider="{weatherInfo}" editable="true">
        <mx:columns>
            <mx:DataGridColumn headerText="tex01" dataField="tex01" editable="true"/>
            <mx:DataGridColumn headerText="tex02" dataField="tex02" editable="true"/>
        </mx:columns>
</mx:DataGrid>

<s:Button id="btn" label="upload" click="buttonHandler(event)" enabled="true"/>
kadin is offline   Reply With Quote
Old 05-23-2012, 06:22 AM   #2
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,299
Send a message via ICQ to wvxvw
Default

ArrayCollection extends Proxy class. Proxy class is meant to be some kind of a precaution step to prevent totally uncontrolled dynamic access to it's fields, however, if you consider the actual implementation of ArrayCollection - this is what happens: random things get written to it's properties.
So, what's happening:
1. You used for-in loop to iterate over properties of array collection. It is by the poor design that the elements of the source of ArrayCollection are available in this way. This particular stupid thing in its design prevents any other programmer from implementing interfaces such as IList and ICollectionView in classes that don't inherit from Proxy.
2. So, purely by chance you got the data you needed, plus the random data that someone decided to put into ArrayCollection properties and this is what you are seeing. Note also that the order is not guaranteed to be the same if you iterate over properties using for-in. So you might actually get different results if doing it like you do.

What you should do:
1. Simplest way is to send the ArrayCollection.source - this is an array where the actual data is stored. But it may not reflect the effective ordering or filtering of the ArrayCollection.
2. So, if you want to also preserve filtering and ordering, you would need to iterate over collection in a for(;;) loop and collect all of its elements into an array. Another approach is to sort and filter the ArrayCollection.source instead of using Sort with ArrayColleciton (I personally find this technique simpler and more efficient - no idea why was Sort created).
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 05-23-2012, 08:34 PM   #3
kadin
Registered User
 
Join Date: Mar 2012
Posts: 29
Default

Thanks for helping me understand.
kadin is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:34 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.