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

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

问题描述



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.

谢谢

Thanks

推荐答案

请尝试为您的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天全站免登陆