-
Can't define a handler/property for NetConnection
Hi Everybody,
I've been having a problem with trying to define a handler on NetConnection so that an when I use Flash Media Server 3 to send a message ( application.broadcastMsg("myHandler","My Message"); ) the clientside picks it up.
I've already got a NetConnection declared and by following the example here... http://livedocs.adobe.com/fms/2/docs...=00000643.html I should simply have to put...
Code:
netConnection=new NetConnection();
netConnection.myHandler = function(msg){
trace(msg);
};
But I get "1119: Access of possibly undefined property myHandler through a reference with static type flash.net:NetConnection"
Here is the whole code which I've been working with an external .as file and linking it as a Document Class
Code:
package
{
import flash.media.Microphone;
import flash.events.NetStatusEvent;
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
public class Test1 extends Sprite{
private var netConnection:NetConnection;
private var rtmpStr:String;
private var nsSubscribe:NetStream;
private var nsPublish:NetStream;
private var microphone:Microphone;
public function TestA (){
rtmpStr="rtmp://***.***.***.***/voicecomms";
attachMicrophone();
netConnection=new NetConnection();
netConnection.testMessage = function(msg){
trace(msg);
};
netConnection.addEventListener (NetStatusEvent.NET_STATUS,checkForConnection);
netConnection.connect(rtmpStr);
}
private function checkForConnection(event:NetStatusEvent):void{
event.info.code == "NetConnection.Connect.Success";
if (event.info.code){
nsPublish=new NetStream(netConnection);
nsPublish.attachAudio (microphone);
var pubNumb = Math.floor(Math.random() * (7000000 - 1 + 1)) + 1;
nsPublish.publish(pubNumb,"live");
nsSubscribe=new NetStream(netConnection);
nsSubscribe.play("user2");
trace("connected");
}
}
private function attachMicrophone(){
microphone=Microphone.getMicrophone();
microphone.gain=80;
microphone.rate=12;
microphone.setSilenceLevel(15,2000);
}
}
}
-
Senior Member
You are mixing up AS2 and AS3 syntax. It must be something like:
netConnection.addEventListener(NetStatusEvent.NET_ STATUS, sHandler);
function sHandler(e:NetStatusEvent):void
{
trace(e.currentTarget.info)// I think it should be info but I am not sure
}
- The right of the People to create Flash movies shall not be infringed. -
-
I found a solution earlier...
PHP Code:
netConnection.client=new Object();
netConnection.client.hasjoined = function (str:String):String
{
trace(str);
return "call back strin: " + str;
}
Seemed to fix it... Now to get the whole thing working.
-
Senior Member
You are using AS2 syntax. That is not correct.
- The right of the People to create Flash movies shall not be infringed. -
-
Hmmm... It works though... I don't know if I'm being really dim but is AS3 really that different from AS2? I don't feel that I know what I'm doing and really bodging my code. I've avoided Flash since the change to AS3 and have only come back to it to create an embedded web voice comm app.
I'll get the hang of it soon enough, but it seems quite different from anything else I've been using.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|