I don't believe you need to disconnect an mxml bind.

Here is a quick and dirty example:

main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical">
     <mx:Script>
         <![CDATA[
             import customcomponents.MyForm;

             private var comboBoxState:String = "";
             private var myForm:MyForm = new MyForm();

             private function createForm():void
             {
                 if(comboBoxState.length > 0)
                 {
                     myForm.comboBoxState = comboBoxState;
                 }
                 addChild(myForm);
             }

             public function saveAndRemoveForm(comboBoxState:String):void
             {
                 this.comboBoxState = comboBoxState;
                 this.removeChild(myForm);
             }
         ]]>
     </mx:Script>
     <mx:Button label="Create Form" click="createForm()"/>
</mx:Application>

customcomponents.MyForm
<?xml version="1.0" encoding="utf-8"?>
<mx:FormItem label="Static droplist"
xmlns:mx="http://www.adobe.com/2006/mxml";
     creationComplete="onCreationComplete()">
     <mx:Script>
         <![CDATA[
             import mx.core.Application;

             public var comboBoxState:String = "";

             private function onCreationComplete():void
             {
                 if(comboBoxState.length > 0)
                 {
                     combo2.selectedItem = comboBoxState;
                 }
             }

             private function onButtonClick():void
             {
                
Application.application.saveAndRemoveForm(combo2.selectedLabel);
             }
         ]]>
     </mx:Script>
     <mx:ComboBox id="combo2" width="100%" labelField="label"
prompt="Select">
         <mx:Array>
             <mx:Object label="original1"/>
             <mx:Object label="original2"/>
         </mx:Array>
     </mx:ComboBox>
     <mx:Button label="Save" click="onButtonClick()"/>
</mx:FormItem>


--- In flexcoders@yahoogroups.com, "dfrank76" <dfrank...@...> wrote:
>
> The state remains if the field does not contain an mxml bind.  For
> example, this droplist below will keep the same state after close.
> I'm just wondering why the mxml binds come back in overpowering
> whatever the user entered and how to stop it.  Is it possible to
> disconnect an mxml bind?
>
>        <mx:FormItem label="Static droplist">
>             <mx:ComboBox id="combo2" width="100%" labelField="label">
>              <mx:Array>
>               <mx:Object label="original1"/>
>               <mx:Object label="original2"/>
>              </mx:Array>
>
>             </mx:ComboBox>
>         </mx:FormItem>
>
> --- In flexcoders@yahoogroups.com, "valdhor" valdhorlists@ wrote:
> >
> > Let me see if I can explain it (And someone else can correct me if I
> > am wrong).
> >
> > In your application you create the loginForm:
> >
> > public var login:MyLoginForm = new MyLoginForm();
> >
> > then with the button you add it to the display list:
> >
> > PopUpManager.addPopUp(login, this, true);
> >
> > When you close the popup:
> >
> > PopUpManager.removePopUp(this);
> >
> > Flex removes it from the Display List. Note that the loginForm
> object
> > still exists (It is in the login variable). When you click the
> button
> > again Flex puts the popup back on the display list and displays it.
> > Anything a user has added to textinputs will still be there. There
> is
> > no logic to save the state of combo boxes (Or check boxes or radio
> > buttons...) so they will default back to the first item in the list.
> >
> > What you would need to do is add logic to save the state of these
> > controls on the click of the close button and then re-instate these
> > saved states when re-opening the loginForm.
> >
> >
> > HTH
> >
> >
> > Steve
> >
> >
> > --- In flexcoders@yahoogroups.com, "dfrank76" <dfrankson@> wrote:
> > >
> > > I am loading data in a popup title window and then I'd like to
> reuse
> > > that title window instance with all the loaded data an user input
> data
> > > any time the user clicks the button to pop it up.  I'm having
> trouble
> > > with bound fields...
> > >
> > > I implemented it using an instance of a custom TitleWindow that is
> > > referenced from the main app, and then use addPopup/removePopup to
> > > show/display it.  In the example below, click the button to pop up
> the
> > > TitleWindow.  Type any text into the TextInput.  Then in the
> ComboBx
> > > either select original2 from the dropdown or click to change the
> > > dataProvider.  Close the popup and reopen and you will see that
> the
> > > text you entered into popup is still there, but any change made to
> the
> > > combo box has been wiped out.
> > >
> > > Is this a bug?  If this is how it is supposed to work, can someone
> > > walk me through why it works this way?  Why are the mxml binds
> > > refreshed when the underlying data they are bound to did not
> change?
> > > Why are the mxml binds wiping out the user entered changes?  Is
> there
> > > any way to prevent this bind refresh from happening?
> > >
> > >
> > >
> > > Below is the simplified example:
> > >
> > > <?xml version="1.0"?>
> > > <!-- MyLoginForm.mxml -->
> > > <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml";>
> > >
> > >     <mx:Script>
> > >         <![CDATA[
> > >             import mx.managers.PopUpManager;
> > >
> > >             [Bindable] private var provider1:XML = <XML><record
> > > label="original1"/><record label="original2"/></XML>;
> > >             [Bindable] private var provider2:XML = <XML><record
> > > label="new1"/><record label="new2"/></XML>;
> > >
> > >             private function swapProviders():void {
> > >                 combo1.dataProvider = provider2.record;
> > >             }
> > >         ]]>
> > >     </mx:Script>
> > >
> > >     <mx:Form>
> > >         <mx:FormItem label="Text field test">
> > >             <mx:TextInput id="text1" width="100%"/>
> > >         </mx:FormItem>
> > >         <mx:FormItem label="Bound droplist">
> > >             <mx:ComboBox id="combo1" width="100%"
> > > dataProvider="{provider1.record}" labelField="@label"/>
> > >         </mx:FormItem>
> > >     </mx:Form>
> > >     <mx:HBox>
> > >         <mx:Button click="swapProviders();" label="Swap data
> > > providers"/>
> > >         <mx:Button label="Close"
> > > click="PopUpManager.removePopUp(this);"/>
> > >     </mx:HBox>
> > > </mx:TitleWindow>
> > >
> > >
> > > <?xml version="1.0"?>
> > > <!-- Main.mxml -->
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
> > >
> > >     <mx:Script>
> > >         <![CDATA[
> > >             import mx.managers.PopUpManager;
> > >             import MyLoginForm;
> > >
> > >             public var login:MyLoginForm = new MyLoginForm();
> > >
> > >             private function showLogin():void {
> > >                 PopUpManager.addPopUp(login, this, true);
> > >             }
> > >         ]]>
> > >     </mx:Script>
> > >
> > >     <mx:VBox width="300" height="300">
> > >         <mx:Button click="showLogin();" label="Login"/>
> > >     </mx:VBox>
> > > </mx:Application>
> > >
> >
>

Reply via email to