Instead of remove child, have you considered just making the component
invisible or visible?
I did something like this using actionscript code, I realize this code
is pretty ugly, but it should give you an idea.
Basically I'm creating the states in actionscript as I loop through
XML. (In this application the information needed for creating the
components is stored in the XML). There are four control buttons that
might or might not be displayed displayed depending on where the user
is while they are paging through the application.
There might be a much easier way for you to do this, but I just wanted
to put this out there and show that it is possible to build states
programatically, and push properties onto the states programatically.
Rob
public function httpResult(event:ResultEvent):void {
states = new Array;
productXML = event.result as XML;
for each (var templateXML:XML in productXML.template ) {
//create a new state for each template view
var templateCount:int = productXML.template.length();
state = new State();
state.name = [EMAIL PROTECTED];
state.overrides.push(new SetProperty(mainPanel ,"title",
[EMAIL PROTECTED]));
tp = new TemplatePage();
//single page design
if (templateXML.childIndex()==0 && templateCount==1){
state.overrides.push(new SetProperty(btnCancel,
"visible", true));
state.overrides.push(new SetProperty(btnNext,
"visible", false));
state.overrides.push(new SetProperty(btnPrevious, "visible",
false));
state.overrides.push(new SetProperty(btnDone,
"visible", true));
}
//this is the first page of a multipage design
else if (templateXML.childIndex()==0 && templateCount
>1){
state.overrides.push(new SetProperty(btnCancel,
"visible", true));
state.overrides.push(new SetProperty(btnNext,
"visible", true));
state.overrides.push(new SetProperty(btnPrevious, "visible",
false));
state.overrides.push(new SetProperty(btnDone,
"visible", false));
}
/this is the last page of a multipage design
else if (templateXML.childIndex() > 0 && templateXML.childIndex()
== templateCount -1 ) {
state.overrides.push(new SetProperty(btnCancel,
"visible", false));
state.overrides.push(new SetProperty(btnNext,
"visible", false));
state.overrides.push(new SetProperty(btnPrevious, "visible",
true));
state.overrides.push(new SetProperty(btnDone,
"visible", true));
//its just a page in the middle
} else {
state.overrides.push(new SetProperty(btnCancel,
"visible", false));
state.overrides.push(new SetProperty(btnNext,
"visible", true));
state.overrides.push(new SetProperty(btnPrevious, "visible",
true));
state.overrides.push(new SetProperty(btnDone,
"visible", false));
}
states.push(state);
}
currentState=State(states[0]).name;
}
On Nov 2, 2008, at 10:08 PM, ashok wrote:
Hi,
I have developed my application to contain multiple states. Each of
the states displays custom components. before moving from one state to
another, I need to remove the components in the previous, state.
The problem is how do i use removechild call for different targets in
the same state.
pseudo code:
<mx:state name="state1">
<mx:removechild id="rmchild1" target="{uicomp1}"/>
<mx:addchild target="{customcomp1}"/>
</mx:state>
<mx:state name="state2">
<mx:removechild id="rmchild2" target="{uicomp2}"/>
<mx:addchild target="{customcomp2}"/>
</mx:state>
<mx:state name="state3">
<mx:removechild id="rmchild3" target="{uicomp3}"/>
<mx:addchild target="{customcomp3}"/>
</mx:state>
This works great when I switch from state1->state2->state3. but when i
want to switch from state2 to state1, my removechild, target should be
my customcomp2 and not uicomp1. How do i bring about this.
I tried to define a function for onEnter for state1, but without any
]effect. can somebody please let me know how do I set the removechild
target dynamically. i tried to accomplish it with the below code, but
it does not work. could somebody please guide me here.
private function onEnterState(statename:String):void
{
switch (prevstate)// this is the stte that the application was
// before changing the state
{
case state2:
this.rmchild1.target = customcomp2;
case state1:
this.rmchild1.target = uicomp1;
}
}
Could somebody point me in the right direction on how to do this? i
searched the docs but was not sucessfull with this.
------------------------------------------
Rob Kunkle
goodLux photography
415.341.5554
Visit us on facebook. Become a fan.