AS3 - 接口(interface)的定义和实现
作者:hangge | 2015-01-30 15:58
在Flex或Flash开发时,常常需要用到接口,下面是一个简单的接口样例。
接口实现:
在MXML中实现接口:
接口定义:
package oreilly.cookbook
{
public interface IDataInterface
{
function set dataType(value:Object):void;
function get dataType():Object;
function update():Boolean;
function write():Boolean;
function readData():Object;
}
}
接口实现:
package oreilly.cookbook
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
public class ClientData extends EventDispatcher implements IDataInterface
{
private var _dataType:Object;
public function ClientData(target:IEventDispatcher=null)
{
super(target);
}
public function set dataType(value:Object):void
{
_dataType = value;
}
//.....
}
}
在MXML中实现接口:
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" implements= "IDataInterface">
全部评论(0)