Step 2: Passing Information to the PopUp
Instead of creating a new dialog window for every question we may come up with, we can instead send information to our
PopUp, making it more dynamic. To do this we use the initObj in the createPopUp function.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script>
<![CDATA[
function openDialog():Void {
var popupParent:MovieClip = this;
var isModal:Boolean = true;
var initObj:Object = { title:"Delete Record" };
var verifyPopUp = mx.managers.PopUpManager.createPopUp( popupParent, warning, isModal, initObj );
verifyPopUp.centerPopUp();
verifyPopUp.lblVerify.text = "Are you sure you want to delete this record?";
}
]]>
</mx:Script>
<mx:Button label="Verify" click="openDialog();" />
</mx:Application>
The initObj variable allows us to modify any property of our TitleWindow, and once we create our
PopUp using the createPopUp function, we can use the variable to modify objects within it.
Compile and run our application, click on the Verify button and you should see your window appear with the new changes. Click Cancel to close it.
Step 3: Receiving Information From A PopUp
In order to receive information back from our PopUp, we need to create an Event that we can raise. This will allow us to send an Object back to our calling application, where the data can be processed.
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.macromedia.com/2003/mxml" width="300" height="120" title="Verify Action" panelBorderStyle="roundCorners">
<mx:Metadata>
[Event("warningResult")]
</mx:Metadata>
<mx:Label id="lblVerify" text="Are you sure you want to do this?" />
<mx:HBox>
<mx:Button label="Ok" />
<mx:Button label="Cancel" click="this.deletePopUp();" />
</mx:HBox>
</mx:TitleWindow>
Next we need to have our application listen for the raised event by adding an Event Listener to our PopUp variable.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script>
<![CDATA[
function openDialog():Void {
var popupParent:MovieClip = this;
var isModal:Boolean = true;
var initObj:Object = { title:"Delete Record" };
var verifyPopUp = mx.managers.PopUpManager.createPopUp( popupParent, warning, isModal, initObj );
verifyPopUp.centerPopUp();
verifyPopUp.lblVerify.text = "Are you sure you want to delete this record?";
verifyPopUp.addEventListener("warningResult", this);
}
]]>
</mx:Script>
<mx:Button label="Verify" click="openDialog();" />
</mx:Application>

