« Congrats Flex team | Main | Blogothon Galaxy goo styles »
July 10, 2006
Array oddity in AMFPHP /Flex 2
Not sure if you want to file this under oddity or stupidity as I might e doing something completely wrong, but either way I discovered some unexpected behaviour.
I've been building a calendar application in Flex for creating,saving,duplicating and deleting events. The backend is php/mysql and I am using amfphp by extending the NetConnection as described in Jesse's post.
All works well but I noticed some weird behaviour when passing an array of items to a php service. Basically the service does a loop through the array an inserts for each item in the array. No biggie, just a standard foreach ($item as $key => $value) type of thing.
However something kept getting oddly screwed up and when I looked in the db, it seemed like an extra value was being entered. I couldn't figure out where this extra value was coming from, because prior to the call to the service, the data was valid.
Thank god for service capture. If you don't own that piece of software, you should. I fired it up and saw that the values being passed to the service included the length of the array along with the values the array contained.
I went back to the service in Flash 8 and tried the same call with the same data. The length value was never passed- so there is something odd going on. I thought about maybe forcing to hide the property on the array, even tho it is most obviously hidden in for loops, but forcing to hide it before sending it might work, but no luck. I did learn the property for hiding properties from the mercy of for loops - setPropertyIsEnumerable method on the Object class.
Anyways something is going on between the two versions - maybe its the way amfphp is used with Flex2.
Ideas? I wrote some server side stuff to handle it, but I'm interested in why this is happening.
Posted by bitch at July 10, 2006 11:50 AM
Comments
There are basically two Array types in AMF0. One which is used for purely index based arrays and one for "mixed" arrays. The first is what was sent over the wire from the Flash 8 player (which did not include an explicit property named length) when you didn't have any "named" properties. The latter does include length as a physical property and is probably how the Flash 9 player is shipping the data.
Posted by: Justin Watkins at July 10, 2006 03:50 PM
I'm sorry that I don't know the answer to your question as I don't use amfphp, but I was wondering: how do you handle date and time editing in Flex 2 when you create or edit an event as there is no Time datatype in AS3?
Posted by: Goose at July 10, 2006 04:06 PM
I have posted more on this subject at
http://www.shockwave-india.com/blog/?archive=2006_07_01_archive.xml#115269365698278650
Posted by: Ragunathan Arul Kumaran at July 17, 2006 04:23 PM
I also noticed this behavior when posting an array to the PHP Service. Essentially, an array, containing MYSQL ID values of [4, 13, 14] looks like this in the POSTDATA /8""41314...
I'm not sure where the 8 is coming from as it doesn't seem like the length, but nonetheless, very strange.
Have you found a solution yet?
Posted by: Justin Levi at August 26, 2006 01:04 AM
In doing development passing arrays from Flex2 through AMFPHP, we noticed it works well if you convert the array to a string first (array.toString), pass it to the PHP function and then use an explode command to convert it back to an array for PHP processing. Hope this helps.
Posted by: Adam Hoffman at August 29, 2006 12:23 PM
Post a comment