0

我看不出这有什么问题。我有一个具有以下代码的 MyConnectionManager 类:

public class MyConnectionManager {
    private var _delegate:NetworkConnectionDelegate;

    public function myfunc():void
    {
        this.delegate.onError(1);  // compile error here!
    }

    public function get delegate():NetworkConnectionDelegate
    {
        return _delegate;
    }

    etc

}

其中 NetworkConnectionDelegate 是一个接口并且有一个方法 onError()

public interface NetworkConnectionDelegate {
    function onError(x:int):void;
}

但是编译器(Flash Builder)说 onError 是编译 MyConnectionManager 时无法访问的方法。为什么编译不出来?

4

2 回答 2

0

接口描述类实例的公共结构。您需要创建类,然后从定义的接口实现它。比如,类:

public class NetworkConnectionDelegate implements IError {
...
    // implements to IError interface
    public function onError(x : int) : void {
    ..
    }
}

界面:

public interface IError {
    function onError(x : int) : void;
}
于 2013-04-30T07:58:17.570 回答
0

belive it or not, the above code is perfectly fine. It was a syntax error in a completely different source file that must have freaked out Flas Builer to cause the compiler error. Once i fixed the totally unrelated error, it compiled just fine. This sort of compile error would never have happened in a decent compiler like VV++ or XCode, but FB seems a liitle flakey. oh well.

于 2013-04-30T14:12:03.867 回答