Search code examples
actionscript-3apache-flexpopupflex3

Flex 3 - Calling a function within a popup component every time it is opened


This will be a really easy one for someone i'm sure. I just need to know the event that will allow me to call a funciton every time the pop up window is opened.

<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"  width="400" 
height="120" title="Change Offer/Event Name" showCloseButton="true" close="PopUpManager.removePopUp(this)"
horizontalScrollPolicy="off" verticalScrollPolicy="off" creationComplete="init()">
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.CloseEvent;
        import mx.managers.PopUpManager;

        private function init():void{
            txtNewName.text = parentApplication.cmbOfferName.selectedItem.TEMPLATENAME;
        }
    ]]>
</mx:Script>

<mx:Canvas width="374" height="74" horizontalScrollPolicy="off" verticalScrollPolicy="off">
    <mx:TextInput id="txtNewName" x="72" y="16" width="240"/>
    <mx:Label x="6" y="18" text="New Name"/>
    <mx:Button x="317" y="16" label="Ok" width="47" click="checkName()"/>
</mx:Canvas>

I have the init() function called in creationComplete which will bring in the value the first time the window is opened but I need it to call the function every time the popup is opened. I have tried, activate, creationComplete, addedToStage, which all dont work.

Oh just to note as well, I cant just set the text input's text property to be bindable to the combobox as I will potentially be selecting from multiple comboboxes depending on what canvas i am viewing.

Thanks in Advance


Solution

  • I managed to solve it myself. I did in fact use 'addedToStage' in the TitleWindow Component. The only problem with using addedToStage is that I was trying to populate a textinput in the popup window so this had not been rendered yet. To get round this I simply added a bindable variable which I added the selected combobox value to and added the variable as the dataprovider for the text field on the textInput.