【问题标题】:flex netconnect ( Property onTest not found on flash.net.NetConnection and there is no default value )flex netconnect(在 flash.net.NetConnection 上找不到属性 onTest 并且没有默认值)
【发布时间】:2023-03-13 04:31:01
【问题描述】:

拥有此代码:

nc.call("test", new Responder(onCallSuccess,onCallFailed), "user1");                

和

public function onTest(id:String):void {
   Alert.show("test called from server");
}

结果:

`ReferenceError: Error #1069: Property onTest not found on flash.net.NetConnection and there is no default value`.

我该如何解决这个问题? 我尝试了很多不同的方法,似乎数据是从服务器应用程序正确发送的,但 flex 不能“吃掉它”

【问题讨论】:

    标签: apache-flex actionscript


    【解决方案1】:

    您需要添加nc.client = this,以便服务器知道在哪里调用方法。

    【讨论】:

      【解决方案2】:

      据我了解,onTest 是回调方法。回调方法必须包含在client 实例的client 属性中。客户端的默认值为NetConnection instance selft。这就是为什么 onTest 试图被调用,但它不存在。您在这里有 2 种可能的解决方案:

      1.用您的自定义类扩展 NetConnection 类并在那里定义onTest 方法。并改用您的自定义类。

      class MyNC extends NetConnection
      {
           public function onTest(id:String) {...}
           ...
      }
      

      2.创建类,它将是NetConnection的客户端并在那里定义onTest。

      class Client
      {
          public function onTest(id:String) {...}
      }
      ...
      var nc:NetConnection = new NetConnection();
      nc.client = new Client();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-08
        • 2022-11-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多