1 Reply Latest reply on Nov 5, 2007 11:38 AM by ntsiii

    Organizing an AS Model - howto?

    harryhoelle
      Hi,

      I have a conceptional question regarding best practice to handle externally loaded XML within ActionScript 3.0 code. How do I organize the data in a useful way?
      Now I have looked though several books and videos on this topic but have only found simple solutions, that don't seem to be the every day scenario as a developer. So let's take a look at my concrete problem and I hope I can help many other developers who are stuck just like me:

      I'm actually using Flex, but there is no big difference for clever ways of handling loaded data.
      I load a complex XML that contains many child nodes via HTTPService and call the resultHandler-function to deal with data received. Here is where the fun begins:
      James Talbot explains on his Total Training video on Flex, that is is smart to always use ArrayCollections as a data structure to store the XML data. I'm wondering, if that's true, because then I can't really use the power of e4x to read the data from my XML. Wouldn't it be better to store the data as a XMLListCollection? What are the disadvantages in this case? What about classes? Should I make a class for each element of my XML that I load and store them in ArrayCollections as I parse through the XML?

      I don't want to pass on the data directly some dataProvider, because I want to work with the data that I received first (eg. calculate averages or sums). The gained information will be used for other Controls.

      Does anyone know some best practice or can briefly explain what to be aware of?

      thanks
      Harry
        • 1. Re: Organizing an AS Model - howto?
          ntsiii Level 3
          It appears that using xml as a dataProvider for very complex UIs, like hundreds of cells in a DataGrid, has some performance and memory use issues. In such a case, you will get better response from the UI, like when scrolling, If your dataProvider is a collection of strongly typed objects. Accessing a property of such an object is significantly faster than accessing an XML attribute. XMLListCOllection will not help this because you are still accessing XML nodes/properties.

          In my personal experience, I have not see this problem, but I do not have any datagrids with 30 columns and hundreds of rows, using complex custom ItemRenderers.

          E4X xml is still the fastest way to get xml from the server. Do NOT leave resultFormat at the default "object". That parse process is slow and rarely useful.

          So no single answer fits all.

          Tracy