Question

I build Adobe Air applications using Flex. After you introduce a few things like list of countries and list of nationalities in ArrayCollection format code gets messy and incredibly long.

Is it possible to place ArrayCollection's into separate files in the same Flex project, and then load them whenever needed, or upon compilation?

Was it helpful?

Solution

Yes; create a class in ActionScript that extends ArrayCollections and then hard codes the ArrayCollection's elements. Perhaps inside the constructor of your new class.

You should be able to use this new class anywhere an ArrayCollection can be used.

More info on creating classes in ActionScript.

OTHER TIPS

So, you implemented an Air Application, which displays/used a large amount of Data. You don't want to hard code this data and you really don't want to extend an ArrayCollection just to move the data outside of the class. This most flexible solution would be stuffing the data into an XML File, compile that into the application and implement a parser to create Objects (or better instances of classes) from the data. This should hidden by an Proxy, Adapter or which pattern you'll like to use.

When you have this functionality, you could potentially reuse it and just have to implement different adapters to data sources like loading the data asynchronously from the file system (or as an asset from the packaged Air application), getting the data from the data base, which ships with Air or use an (web) service (JSON, XML, AMF). This might be a good exercise to get you application more modular and make it easier to test.

When it comes to inheritance, you should favor composition over inheritance. That's a common best practice in designing applications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top