简体   繁体   English

在FLEX 3,ActionScript 3.0中使用ActionScript类和接口时出现错误

[英]Getting Error when working with ActionScript Class and Interface in FLEX 3, ActionScript 3.0

I am currently new in ActionScript and I am creating an Interface and Class where class implements Interface. 我目前是ActionScript的新手,我正在创建一个实现类的Interface和Class。 I have created Interface and Class both in src/com folder. 我已经在src / com文件夹中创建了Interface和Class。 Here is the code what I did till now. 这是我到目前为止所做的代码。

Interface 接口

package com
{
    public interface TestData
    {
        function getInput(str:String):void
        function getOutput():String
    }
}

Class

package com
{
    public class EntityEL implements TestData
    {
        public var uname:String;

        function getOutput():String
        {
            return uname;
        }

        function getInput(str:String):void
        {
            uname = str;
        }

        public function EntityEL()
        {

        }
    }
}

mxml file mxml文件

public var etn:EntityEL = new EntityEL();

public function btnClick():void
        {
            etn.getInput(value.text);
            Alert.show(etn.getOutput());
        }


<mx:Button label="Button Click" click="{btnClick();}" />
<mx:TextInput id="value" />

I am getting an error " 1044: Interface method getInput in namespace com:TestData not implemented by class com:EntityEL. " 我收到一个错误“ 1044:名称空间com:TestData中的接口方法getInput未由类com:EntityEL实现。

Please Help me to solve this problem. 请帮我解决这个问题。

The idea of an interface is to define a contract between the caller and callee objects: Which methods can be accessed, which parameters are required, and what kind of data will be returned. 接口的概念是定义调用方和被调用方对象之间的协定:可以访问哪些方法,需要哪些参数以及将返回哪种数据。

In order for that contract to make any sense, these methods have to be accessible, so that the "outside world" is allowed to call them. 为了使该合同有意义,必须使用这些方法,以便“外部世界”可以调用它们。

When you omit access modifiers, the Flex compiler assumes internal as the default, which means that classes from within the same package have permission to access the methods - and so to some extent, this contract seems fulfilled. 省略访问修饰符时,Flex编译器会将internal设为默认值,这意味着同一包中的类具有访问方法的权限-因此在某种程度上,该合同似乎已实现。 The same would be true for any other namespace. 对于任何其他名称空间,也是如此。

Strangely enough, Adobe clearly doesn't allow it : Your method implementations have to be public . 奇怪的是, Adobe显然不允许这样做您的方法实现必须是 public

However, you can declare your interface as internal , so that only classes from the package are allowed to implement it, and that leaves a way to keep your API internal, as well - if that was your intent. 但是,您可以将接口声明为internal ,以便仅允许包中的类实现该接口,并且这也可以使API保持内部状态(如果您这样做的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM