Skip to main content
January 24, 2009
Question

How to Call a function from FMS to AS3

  • January 24, 2009
  • 1 reply
  • 671 views
Hi,
I am using Windows operating system, Flash CS3 and FMS 3.5. I am new to Action Script 3.0 But I am good in Action Script 2.0.

I am trying to call a function declared in Action Script 3.0 from FMS. here I have declared it as follows.
In FMS I am calling a function as
application.onConnect(client){

client.call("informServer");
};

In Flash AS 3 I have declared this function as follows.
var nc = new NetConnection();
// Now here I declare function
nc.addEventListener("informServer", informServerHandler);
nc.connect("rtmp://localhost/abc");

private function informServerHandler(evt){
trace(" Till here Done ");
}

So When I execute Flash file then it connects to FMS and also in NetStatus event of NetConnection I got Connected.
But Then I got Error in Flash as

Error #2095: flash.net.NetConnection was unable to invoke callback informServer." error=ReferenceError: Error #1069: Property informServer not found on flash.net.NetConnection and there is no default value.]

Please tell me Have I not declared the Function in AS 3 properly or I am doing something wrong. Please Some one help me...

Thanks in advance.
    This topic has been closed for replies.

    1 reply

    January 25, 2009
    You can't add an event listener, as your custom method is not a method of the NetConnection class. Instead, you can assign methods to the NetConnection's client property:

    nc.client.informServer = function(){
    // do something
    }

    If you want to just define your functions in a class, you can make the class the value of nc.client:

    class blah{

    function blah(){
    var nc:NetConnection = new NetConnection()
    nc.client=this;
    //connect, status listener, etc
    }

    private function informServer(){
    // Now this function is invoked, since the class is the NetConnection's client.
    }


    }