5 Replies Latest reply on Jul 17, 2011 7:34 PM by huan huan

    Can I pass "constructor" parameters to custom mxml component

    Fred in Orlando Level 1

      I would like to create a generic dialog (popup)  using mxml and then have my application specific dialogs subclass it.  I would like to pass it at least one parameter at instantiation, so it has the reference to it's parent window.  My code looks like this so far

       

            private static var DebugPopup:DebugViewer;
        

        public static function creationComplete(event:Event):void {
            MainWindow = event.target as DisplayObject;
               DebugPopup = new DebugViewer(MainWindow);  //only works if no parameters passed
        }

      ----------------DebugViewer.mxml looks like this--------- some code deleted for brevity------------------------------

       

      <mx:TitleWindow>

      <mx:Script>  <![CDATA[
         import mx.managers.PopUpManager;
        
         [Bindable]   public var ParentWindow:DisplayObject;
        

         [Bindable]   public var buffer:String= "Insert output here\n";
        
         public function log(text:Object):void {    buffer += text+"\n";   }
        
         public function show( parent:DisplayObject):void {
          PopUpManager.addPopUp(this, parent);
                PopUpManager.centerPopUp(this);
         
         }
        ]]> </mx:Script>
      <mx:TextArea width="400" height="300" text="{buffer}"/>

      </mx:TitleWindow>

      I would like to define the parent window when I instantiate the dialog, rather than pass it via the show method.  Is there a way to do this in an mxml component or do I need to go to ActionScript.  I plan to make this a general Dialog class that is then subclssed by all my application specific dialogs.