如何在 flex 中调用具有附加功能的自定义组件 [英] how do I call a customcomponent with added functionality in flex

查看:28
本文介绍了如何在 flex 中调用具有附加功能的自定义组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义组件(名为customtitlewindow),其代码如下:

I have created a custom component (named customtitlewindow) the code of which is as follows:

<?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),它像这样调用上面的:

Now I again created a component (named deleteconfirm) which calls the above one like this:

<?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>

(在主文件中)现在点击一个按钮,我调用上面的(第二个)如下:

(in main file) Now on the click of a button I am calling the above (second one) as follows:

<?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>

我的主要目的是,对于向最终用户显示的所有弹出窗口,当按下退出键时,所有弹出窗口都将关闭,并在单击标题栏上显示的关闭按钮时关闭所有弹出窗口.

The main purpose of mine is that for all the popup windows shown to end user all of them be closed when the escape key is pressed and all of them be closed upon click of the closebutton displayed at the titlebar.

但是在退出键"上按什么都没有发生.
我该怎么做?
怎么了?请纠正我上面的错误.

But on the "escape key" press nothing is happening.
How can I do this?
What is wrong? Please correct me where ever I am wrong above.

谢谢

推荐答案

尝试为您的 deleteconfirm 类执行此操作:

Try doing this for your deleteconfirm class:

<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>

此外,您应该考虑遵守适当的标准,例如类的大写(而不是 deleteconfirm,它应该是 DeleteConfirm;并且更具描述性也无妨).

Also, you should look into adhering to proper standards like uppercasing on classes (instead of deleteconfirm, it should be DeleteConfirm; and it wouldn't hurt to be more descriptive).

这篇关于如何在 flex 中调用具有附加功能的自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆