1 Reply Latest reply on Feb 4, 2010 9:34 PM by suxuekun

    Where to write connection code?

    satheeshpallath12 Level 1

      Hai,

       

      In Flex,where we have to write the stratus connection code?

      Is it outside the script or inside?

        • 1. Re: Where to write connection code?
          suxuekun

          you can download some samples to see how to build a application to connect

          to stratus.

           

          use

          <mx:Script >

          <![CDATA[

          // action script code here

           

          ]]>

          </mx:Script>

           

          to write your as3 code

          or just

          <mx:Script source="yourAScodeFile.as"/>

          and write your code in yourAScodeFIle.as.

           

          e.g.

          //I don't use debug ver so I use Alert.show() instead of trace();

           

          myapp.mxml

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

          creationComplete="connect()">

          <mx:Script source="myapp.as"/>

          <mx:Button id="conn" label="connect" click="connect"/>

          </mx:Application>

           

          myapp.as

           

          import flash.events.NetStatusEvent;

          import flash.net.NetConnection;

          import mx.controls.Alert;

           

          private const StratusAddress:String = "rtmfp://stratus.adobe.com";

          private const DeveloperKey:String = "yourDevelopKey";

          private var nc:NetConnection;

           

          private function connect():void

          {

          nc = new NetConnection();

          nc.addEventListener(NetStatusEvent.NET_STATUS,netConnectionHandler);

          nc.connect(StratusAddress + "/" + DeveloperKey);

          }

           

          private function netConnectionHandler(event:NetStatusEvent):void

          {

          Alert.show(event.info.code,"info code");

          Alert.show(nc.nearID,"peer id");

          }