I am currently new in ActionScript and I am creating an Interface and Class where class implements Interface.
I have created Interface and Class both in src/com folder. 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
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.“
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
internalas 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. The same would be true for any other namespace.Strangely enough, Adobe clearly doesn’t allow it: Your method implementations have to be
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.