2011-04-08 50 views
0

添加了功能的customcomponent我創建了一個自定義組件(名爲customtitlewindow)的代碼,其中如下:我怎麼叫的柔性

<?xml version="1.0" encoding="utf-8"?> 
<mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" layout="vertical" width="400" height="300" 
       xmlns:comp="components.*" 
       showCloseButton="true" 
       keyDown="detectescapekeypress(event)" 
       creationComplete="this.setFocus();" 
       close="PopUpManager.removePopUp(this);" 
       paddingTop="40"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.managers.PopUpManager; 
      public function detectescapekeypress(event:KeyboardEvent):void 
      { 
       if(event.charCode == Keyboard.ESCAPE) 
       { 
        PopUpManager.removePopUp(this); 
       } 
      } 
     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

</mx:TitleWindow> 

現在我又創建了一個組件(名爲deleteconfirm)的調用上面的一個是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Container xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" xmlns:components="components.*"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 
     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

    <components:customtitlewindow title="custom title window"> 
     <s:Label> 
      <s:text>this is the custom text for deleteconfirm.</s:text> 
     </s:Label> 
     <s:Button label="ok"> 
      <s:click> 
       <![CDATA[ 
        Alert.show("Hello world!", "title"); 
       ]]> 
      </s:click> 
     </s:Button> 
    </components:customtitlewindow> 
</mx:Container> 

(主文件)現在上的按鈕,我呼籲上述(第二個)的點擊如下:

<?xml version="1.0" encoding="utf-8"?> 
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> 
    <mx:Script> 
    <![CDATA[ 
      import mx.managers.PopUpManager; 
     ]]> 
    </mx:Script> 
    <mx:VBox width="100%" height="100%"> 
    <mx:Button label="Delete Record"> 
     <mx:click> 
      <![CDATA[ 
       var ctd:deleteconfirm = new deleteconfirm(); 
       ctd = deleteconfirm(PopUpManager.createPopUp(this, deleteconfirm, true)); 
      ]]> 
     </mx:click> 
    </mx:Button> 
    </mx:VBox> 
</mx:WindowedApplication> 

我的主要目的是爲了向最終用戶顯示的所有彈出窗口在按下退出鍵時關閉所有彈出窗口,並在點擊標題欄上顯示的關閉按鈕時關閉所有彈出窗口。

但在「退出鍵」上按下什麼都沒有發生。
我該怎麼做?
有什麼不對?請糾正我以往任何地方錯誤的地方。

謝謝

回答

1

您正試圖刪除錯誤的popUp引用。

正在創建的彈出是deleteconfirm類的實例,但是當你試圖將其刪除,在detectescapekeypress()函數,您是從customtitlewindow類傳遞一個實例。

簡單的方法解決它是通過在detectescapekeypress改變這一行()

PopUpManager.removePopUp(IFlexDisplayObject(this.parent)); 

解決它的最好的方式,將是移動的按鍵操作到刪除確認類。

+0

感謝您的回答,但我認爲您的解決方案會打敗我的問題的目的。我不想重複escapekeysequence的代碼。 – 2011-04-10 10:47:37

2

嘗試這樣做你的deleteconfirm類:

<components:customtitlewindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" xmlns:components="components.*" title="custom title window"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 
     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

     <s:Label> 
      <s:text>this is the custom text for deleteconfirm.</s:text> 
     </s:Label> 
     <s:Button label="ok"> 
      <s:click> 
       <![CDATA[ 
        Alert.show("Hello world!", "title"); 
       ]]> 
      </s:click> 
     </s:Button> 
</components:customtitlewindow> 

此外,你應該看看秉承像uppercasing類上(而不是deleteconfirm,它應該是DeleteConfirm適當標準;而且它不會傷害更具描述性)。

+1

+1用於遵守大寫標準和描述性命名。 :) – 2011-04-08 15:18:52

+0

當我單擊刪除按鈕時出現此錯誤:「已爲此組件指定了多組可視子項(基本組件定義和派生組件定義)」。谷歌搜索這一點,我認爲這是不可能的。有任何想法嗎? – 2011-04-12 07:12:32

+0

嘗試這樣做:'' – 2011-04-12 11:47:26