I'm trying to create a part of the UI that programmatically renders itself in response to data coming from a service. This represents some questions we want to present to the user and once they answer these it may lead to more questions and so on. Here's how it works so far.
The user clicks a button that triggers the initial event. 1) The event maps to a command that invokes an RPC service to get the array of questions. There's an Id here that the backend uses to track which set of questions you are on. 2) The result handler for the command caches the array on the model locator and sets the viewState index to the DynamicPanel.mxml 3) The panel is drawn and addedToStage() runs a local function that has the magic actionscript to walk the model.array calling addChild(). After painting the questions it adds a submit button. 4) The use enters data and clicks submit 5) Submit raises a 2nd event which triggers another command that posts the answers back to the service and in its result handler raises the #1 event again a) This causes the questionService.get() to run a 2nd time and retrieve the next set of questions from the backend b) The view is switched (ala #2 above) and nothing happens. I'm guessing one of 2 things is wrong here. 1) addedToStage() only runs once so we'll never see more than the 1st question set 2) possibly as I'm already on the view state (DynamicPanl.mxml) for the questions then 2nd time round it doesn't trigger a switch over at all (but if it did the addedToStage function might run) It'd be great if someone could suggest a way round this. I don't want to have multiple views such as VIEW_SET_1, VIEW_SET_2 SET_N as I don't know in advance how many question sets there might be. Also data services might be an option to have the question set exposed as a managed array but that doesn't work well with the current backend API and that's not easy to change. TIA.

