2011-04-08 53 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