2 Replies Latest reply on Jul 8, 2009 11:16 AM by injpix

    Object-oriented question

    Zolotoj Level 3

      I have the following generic mxml component named customPopupWindow:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow
      
       xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"close="PopUpManager.removePopUp(
      
      this)" showCloseButton="true" borderStyle="solid" borderThickness="2"headerColors="
      
      [#000000,#D2CEB2]" minHeight="200" minWidth="300"backgroundColor="
      
      #F8F8DD" verticalAlign="top">
      
      <mx:Script>
      <![CDATA[
      
      
      import mx.managers.PopUpManager; ]]>
      
      
      </mx:Script> 
      </mx:TitleWindow>
      
      
      
      

      I am subclassing it like this:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <modulecode:customPopupWindow
      
       xmlns:fx="
      
      http://ns.adobe.com/mxml/2009" xmlns:s="
      
      library://ns.adobe.com/flex/spark" xmlns:mx="
      
      library://ns.adobe.com/flex/halo" 
      xmlns:modulecode="
      modulecode.*" width="
      
      500" height="400">
      
      <fx:Script>
      <![CDATA[
      
      import mx.controls.DataGrid;
      
      import mx.events.ListEvent;
      
      import mx.managers.PopUpManager;
      
      public var documentGrid:DataGrid;
      
      private function selectDocument(event:ListEvent):void{
      
      PopUpManager.removePopUp(this);} 
      ]]>
      
      
      </fx:Script>
      
      <mx:Tree id="documentTree" fontSize="10" width="100%" height="99%"labelField="
      
      @name" textAlign="left"itemDoubleClick="selectDocument(event);" doubleClickEnabled="
      
      true"showRoot="
      
      true" borderStyle="solid" borderThickness="1">
      
      </mx:Tree></modulecode:customPopupWindow>
      
      
      
      
      
      

      Why do I need import mx.managers.PopUpManager line?

      It has been implemented in the  base class.

       

      Thanks

        • 1. Re: Object-oriented question
          rtalton Level 4

          Because you need the popup manager whenever you call one of its methods, like addPopUp or removePopUp. Since you are actually removing it from within the second component, you don't need it in the first.

          • 2. Re: Object-oriented question
            injpix Level 3

            Or, an alternative to rtalton suggestion, would be to keep PopUpManager.removePopUp(this)in the base class and create a wrapper function in the subclass that will invoke it.  By having a wrapper function in the subclass you will not need to import PopUpManager, the import will need to be done in the base class. 

            1 person found this helpful