0 Replies Latest reply on Apr 30, 2007 7:01 AM by Fred in Orlando

    MVC and data from a modal dialog

    Fred in Orlando
      I would like to establish a standard design pattern for all dialogs in my project. I'm not sure of the cleanest way to get the data out of the dialog after the user selects "OK". I don't want to have the main program be aware of the structure of the dialog but just get the relevant data. Here is a snippet of what I've got so far.

      The "ApproveFunction" is passed in from the main controller, which the dialog calls when OK is selected.
      My problems are:
      1. can I pass the <mx:Model/> to the ApproveFunction, and if so how does it reference it?
      2. Should I use a class instance to pass the data back instead?
      Any advice would be greatly appreciated.


      <mx:Script> <![CDATA[
      import mx.managers.PopUpManager;
      import mx.controls.*;
      import mx.events.*;

      private var ApproveFunction:Function;

      private function okClicked():void {
      // note use of static below, allows me to execute "myDialog.show(........) which I like since it matches the Alert model.
      public static function show(parent:DisplayObject, approveFunction:Function, initialparms:Object):void {
      var dialog:myDialog=DeletePunchDialog(PopUpManager.createPopUp( parent, myDialog , true));
      dialog.ApproveFunction = approveFunction;
      dialog.time.text = initialparms.time;
      dialog.punchid.text = initialparms.id;

      ]]> </mx:Script>

      <mx:Model id="parms">

      <mx:Form >
      <mx:FormItem label="Record Id" > <mx:TextInput id="punchid"/> </mx:FormItem>
      <mx:FormItem label="Time" > <mx:TextInput id="time"/> </mx:FormItem>
      <mx:FormItem label="Explanation"> <mx:TextArea id="explanation" /> </mx:FormItem>
      <mx:FormItem > <mx:HBox>
      <mx:Button label="OK" click="okClicked();"/>
      <mx:Button label="Cancel" click="mx.managers.PopUpManager.removePopUp(this);"/>
      </mx:HBox> </mx:FormItem>