1

我有一个加载到另一部电影中的 mxml 应用程序。这需要它实现某些功能。是否可以让 mxml 应用程序的主类来实现接口?如果是,如何?

4

2 回答 2

3

每个 mxml 组件(以及Application)都有implements可以添加接口的属性。这是示例:

应用程序.mxml:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600"
               implements="IInterface">
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <fx:Script>
        <![CDATA[

            public function one():void
            {
                // TODO Auto Generated method stub

            }

            public function get prop():String
            {
                // TODO Auto Generated method stub
                return null;
            }

            public function set prop(value:String)
            {
                // TODO Auto Generated method stub
                return null;
            }

        ]]>
    </fx:Script>


</s:Application>

IInterface.as:

package
{
    public interface IInterface
    {
        function one():void;

        function get prop():String;
        function set prop(value:String);
    }
}
于 2012-04-18T10:45:04.113 回答
0

请尝试这样的事情: - 希望下面的代码可以帮助你 -

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               implements="pkgCom.IAlpha">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[

            public function updateName():void {
                //code
            }
            public function updateValue():void {
                //code
            }
            public function updateValue1():void {
                //code
            }

        ]]>
    </fx:Script>
</s:Application>

接口名称:- IAlpha 包名称:- pkgCom

package pkgCom
{
    public interface IAlpha {
        function updateName():void;
        function updateValue():void;
        function updateValue1():void;
    }
}
于 2012-04-18T12:11:56.643 回答