I build my first application like this to connec to stratus;
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="connect()">
// ActionScript file
private const StratusAddress:String = "rtmfp://stratus.adobe.com";
private const DeveloperKey:String = "my developerKey";
private var nc:NetConnection;
private var sendStream:NetStream;
private var recvStream:NetStream;
private function connect():void
nc = new NetConnection();
nc.connect(StratusAddress + "/" + DeveloperKey);
private function netConnectionHandler(event:NetStatusEvent):void
I got the message
at this line ~~Alert.show(event.info.code);
but I can't get nc.nearID;
is there something wrong in my code ? or what should I do to get my nc.nearID?
i don't see anything outwardly wrong with your code. do you get some kind of exception when you access NetConnection.nearID? did you remember to set your project to target Flash Player 10 when you build it, so that the nearID property is visible?
thank you for your help mike.But I think I have did it.
flex builder 3
I have changed lines below
<!-- keep the original location in the libpath for backwards-compatibility -->
I think that's all to do for Flash Player 10 ver.
anything I missed?
if it's not for FP10. it should tell me that nc.nearID is not defined or something else ,because 9ver doesn't have nc.nearID.
in fact after that code I have
sendStream = new NetStream(nc,NetStream.DIRECT_CONNECTIONS);
and something like
private function getconnect(id:String):void
recvStream = new NetStream(nc,id);
if it's not for 10 ver . it should tell me that there are some problems. because netStream(NetConnection,peerID) only have one parameter in FP9
but it runs successfully without any problem except I can't get nc.nearID. so I think I have set my project to target Flash Player 10 .
ok, so you are clearly targeting the correct version of Flash Player. now the question is: when you try to access NetConnection.nearID, what *are* you getting? an exception? a blank? is your failure simply that a second flex Alert box isn't showing up? or is it showing up but it's empty?
It doesn't show up.
I get nothing.
Alert.show(event.info.code)//netConnection.Connect.success --- now here it's ok
Alert.show(nc.nearID)//nothing just nothing ,not empty --- it stoped here,I think
Alert.show("hello,hello")//nothing --- can't reach here.
perhaps Flex SDK 3.2.0 doesn't let you stack two alert boxes on top of each other. i was able to stack them with SDK 3.4.0. if you're not getting the second box, then one of two situations must be occurring: NetConnection.nearID is throwing an exception so you never get to create the Alert box, or the Alert box just isn't being displayed but there's no actual problem accessing NetConnection.nearID.
i recommend either only popping one Alert box up (perhaps combine the event code and the nearID into one string?) or use some other way of communicating the nearID to the user. perhaps a Flex text field or something that you set, or a String variable that you've bound with a text field and then set the variable to the nearID.
once I did a stupid thing like this
timer = new Timer(10);
private function onTimer(event:TimerEvent):void
/// er .so , it's not this problem
And I also has this app download from adobe
and it has
status("Connected, my ID: " + netConnection.nearID + "\n");
private function status(msg:String):void
statusArea.text += msg;
statusArea.verticalScrollPosition = statusArea.textHeight;
trace("ScriptDebug: " + msg);
I also get nothing on the textarea;
so I think it's just something wrong that the peerID isn't returned.......
i took your code as originally posted and copy-pasted it into a new Flex project (separate .mxml and .as). the only changes i made were 1) i used my default Flex SDK (3.4.0-9271 MPL) and 2) i substituted my own Stratus developer key for "my developerKey" in your code. i then changed the compiler "require Flash version" to 10.0.0 and ran it in my browser (with Flash Player 10,0,42,34). i got two alert boxes, one with my nearID and one with "NetConnection.Connect.Success".
since you say execution of your netConnectionHandler function stops after dispatching the first Alert box, and you later indicate that you don't dispatch a third Alert box after trying to access nc.nearID, the only conclusion is that trying to access nc.nearID is raising an exception.
once you have *double checked* that you are running this in Flash Player 10.0 or above, the next step is to determine what exception you are getting. you can wrap your access of nc.nearID in a try/catch block and if it raises an exception, print out what the exception is. you could also install a debug Flash Player, which should print out the exception in a dialog box. even better would be to run the app in the Flex Builder debugger.