Search code examples
actionscript-3apache-flexcomboboxdatefieldtabnavigator

Flex - Clearing DateField value on tab change in TabNavigator


I have the following tab navigator, which has a Project tab, containing a Combobox next to Release label as follows(AdditionalDetails.mxml): enter image description here

Same tab navigator is having a Gate2 tab, which contains a DateField next to the label CERT load date, which can be seen below(Gate2.mxml): enter image description here

Now, when I select Release as TBD on Project tab, an alert box appears as follows: enter image description here

On clicking YES, I want to clear the DateField on Gate2 tab. How can I do so? Code for Combobox(AdditionalDetails.mxml):

<mx:ComboBox id="General_Release_Dates"
                     selectedItem="{modelProxy.General_Release_Dates}"
                     valueCommit="{model.General_Release_Dates = event.currentTarget.selectedItem;updateReleaseDate(event)}"
                     change="{model.General_Release_Dates = event.currentTarget.selectedItem;updateReleaseDate(event)}" close="closeHandler(event);" includeInLayout="true" visible="true">
        </mx:ComboBox

Code for handling YES click on Alert box:

private function alertClickHandler(evt:CloseEvent):void {
if (evt.detail == Alert.YES) { //Code to clear DateField}

DateField code on Gate2 tab(Gate2.mxml): DateField code:<mx:DateField id="G2_CRTLoadDate" width="150" selectedDate="{modelProxy.G2_CRTLoadDate}" change="{modelProxy.G2_CRTLoadDate = event.currentTarget.selectedDate;changeManagerStatus()}"/>


Solution

  • Updated: Aug 31 23:27(JST)

    If you're using singleton Flex - Problems in accessing static variable on another mxml page

    1) Create variable at your MySingleton class like below.

        private var _gate2:Object;
    
        public function set gate2(value:Object):void
        {
            _gate2 = value;
        } 
    
        public function get gate2():Object
        {
            return _gate2; 
        }
    

    2) Gate2.mxml (write at creationComplete event)

    singleton.gate2 = this;
    

    3) Control Gate2 from external class.

    private function alertClickHandler(evt:CloseEvent):void {
        if (evt.detail == Alert.YES) {
            //Code to clear DateField
    
            singleton.gate2.G2_CRTLoadDate.selectedDate = null;
        }
    }