You can use both methods. Use MXML for containers which won't change and will hold your UI elements dynamically created using AS.
Thanks for answering.
Let me restructure how I've asked this.
Let's say I have four main components in my app. And let's say I want to be able to configure in a database somewhere which users see which components.
User 1 sees all four.
User 2 sees components 1 and 3
User 3 sees components 2 and 4
User 4 sees only component 2.
Problem is, if I create the components in mxml, they all get created and displayed before my web service gets back with the display options.
What's the best practice for doing this?
1 person found this helpful
I would say "it depends".
If the components are large, you could define them in separate modules and
load the modules based on the db query. The main app would just show
something temporary until it figured out which module to load. The module
could still be defined in MXML.
Another way would be states if you aren't otherwise using states in the app.
Then you could still use MXML.
I'm probably misunderstanding something here. Correct me.
You say "load the modules based on the db query". But the the db query returns results after the modules have already been loaded. I don't know of a way to stop the modules from loading if they've been created in mxml. If I make them in ActionScript I get to decide when they get loaded. I can make the web service call, and onResult I can load components. If I make the components in mxml though it seems the Flex framework loads the components on its own schedule. That's the problem I'm describing here. The web service call appears to be asynchronous and UI construction appears to go on while the web service call is being executed.
If I create a custom component in a separate file but then add an instance of it in mxml in my main app file, how do I keep Flex from constructing it until my data is retrieved? Probably something simple here that I'm not seeing.
I was picturing that you would set the moduleLoader's url property based on
the query. You would not set it in MXML.
You also have the choice of using creationPolicy and navigators like
ViewStack. Modules would be more lightweight though.
If you use states, the components in a state do not get created until you
switch to that state.
I see. Yes, I'm already making my web service call in the preinitialize() function. It still returns late with the data needed to config the the app.
I'm looking into the state thing. My app has six as it is though. I'm using them to allow a remote "controller" app to change a user's view (resize and rearrange screen components).
There are six screen arrangement view states now. If I use states to account for adding or removing components too, I'll quickly balloon that number to 20 or 30. I've read posts from people who've said they have that many states but something feels odd about it.
Seems like I should be using view states to rearrange the user's view as I do now, but that including or not including certain components in the app should be handled in some other way. Just haven't figured out a best practice here yet.