Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 如何在flex中调用具有附加功能的customcomponent_Apache Flex_Mxml_Code Reuse_Custom Component_Reusability - Fatal编程技术网

Apache flex 如何在flex中调用具有附加功能的customcomponent

Apache flex 如何在flex中调用具有附加功能的customcomponent,apache-flex,mxml,code-reuse,custom-component,reusability,Apache Flex,Mxml,Code Reuse,Custom Component,Reusability,我创建了一个自定义组件(名为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.adob

我创建了一个自定义组件(名为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>
<?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>

现在,我再次创建了一个组件(名为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>

这是deleteconfirm的自定义文本。
(在主文件中)现在单击一个按钮,我调用上面的(第二个),如下所示:

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

我的主要目的是,对于显示给最终用户的所有弹出窗口,当按下escape键时,所有窗口都将关闭,单击标题栏上显示的Close(关闭)按钮时,所有窗口都将关闭

但按“退出键”时,什么也没有发生。
我该怎么做?
怎么了?请纠正我上面的错误


谢谢

您试图删除错误的弹出引用

您正在创建的弹出窗口是deleteconfirm类的一个实例,但是当您尝试删除它时,在detectescapekeypress()函数上,您正在传递customtitlewindow类的一个实例

解决此问题的一个简单方法是在DetectCapeKeyPress()中更改此行:


修复此问题的最佳方法是将按键处理移动到deleteconfirm类。

您试图删除错误的弹出引用

您正在创建的弹出窗口是deleteconfirm类的一个实例,但是当您尝试删除它时,在detectescapekeypress()函数上,您正在传递customtitlewindow类的一个实例

解决此问题的一个简单方法是在DetectCapeKeyPress()中更改此行:


解决此问题的最佳方法是将按键处理移动到deleteconfirm类。

尝试对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>

这是deleteconfirm的自定义文本。

此外,您还应该注意遵守适当的标准,如类的大写字母(而不是deleteconfirm,它应该是deleteconfirm;更具描述性也无妨)。

尝试对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>

这是deleteconfirm的自定义文本。

此外,您还应该注意遵守适当的标准,如类上的大写字母(而不是deleteconfirm,它应该是deleteconfirm;更具描述性也无妨)。

+1用于遵守大写字母标准和描述性命名。:)当我点击删除按钮时,我发现了这个错误:“已经为这个组件(基本组件定义和派生组件定义)指定了多组可视子组件。”谷歌搜索到了这个问题,我认为这是不可能的。有什么想法吗?试着这样做:
+1用于遵守大写标准和描述性命名。:)当我点击删除按钮时,我发现了这个错误:“已经为这个组件(基本组件定义和派生组件定义)指定了多组可视子组件。”谷歌搜索到了这个问题,我认为这是不可能的。有什么想法吗?试着这样做:
谢谢你的回答,但我认为你的解决方案会破坏我问题的目的。我不想重复escapekeysequence的代码。谢谢你的回答,但我认为你的解决方案会破坏我问题的目的。我不想重复escapekeysequence的代码。