May 2, 2007
by Branden
As I mentioned in the opening post, I’m not a Flex-head. I just haven’t had a chance yet to really dig into the API. This fact, combined with Keenan’s knowlege of Flex just resulted in a very funny argument.
Keenan is building a small Flex app for one of our clients to allow them to create levels for an education game we wrote for them. The game reads in XML files that follow a specialized schema we created. Whoop-de-doo, right?
Well, it got interesting when Keenan was loading the data. Since I really only know AS3 I assumed he was using the 1-2 punch of URLRequest and URLLoader. I then assumed he was taking the raw data from that load and create a new XML object. Nope.
Keenan was using Flex’s HTTPService class. With that class you need to specify how you want it to treat the data it pulls down – the resultFormat. By default it takes XML and turns it into a simple object structure and Keenan was just using the default.
That simple object structure is just enough like E4X it was throwing me off. You can step right through the structure just like it was E4X. Since the code wasn’t using any of the specialized E4X stuff like @ or filtering I couldn’t tell just by looking that he wasn’t actually using E4X.
The problem was that HTTPService, when it runs into a single tag that doesn’t repeat, just creates a single object – while E4X will still create a XMLList. So, when Keenan was trying to access a tag there just happened to be one of, the length property didn’t exist.
I was thinking he hadn’t ever created an actual XML object (he hadn’t) so that’s why it wasn’t working. Keenan thought that he should be getting an array – and he should of – if he was using XML!






no comments