【发布时间】:2011-04-08 10:29:01
【问题描述】:
我创建了一个自定义组件(名为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>
我的主要目的是,所有显示给最终用户的弹出窗口都在按下退出键时关闭,并且在点击标题栏上显示的关闭按钮时全部关闭。
但是在“退出键”上按什么都没有发生。
我该怎么做?
怎么了?请纠正我上面的错误。
谢谢
【问题讨论】:
标签: apache-flex mxml code-reuse custom-component reusability