768x90 Getting Online Shouldn't be Tough- $7.49 .com Domains at Go Daddy

SharedObject in Sever Using NetConnection or by Remote

A few days ago i have problem how to implement my live streaming using SharedObject in Red5 because usually SharedObject, as i know, only good implementable for local only (like getting or store cookies), before implemented to my live streaming application, i created simple chat application to remote SharedObject :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="creationComplete()">
<mx:Script source="streaming.as"/>
<mx:TextInput x="10" y="10" id="rtmpUrl" text="your rtmp address"/>
<mx:Button x="216" y="10" id="connectBtn"/>
<mx:TextInput x="10" y="269" id="enterMsg" />
<mx:TextArea x="10" y="40" height="221" id="msgBoard" width="222" />
<mx:Button x="178" y="269" id="sendBtn"/>
</mx:Application>

And now let create streaming.as script :
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.SyncEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.SharedObject;

import mx.controls.Alert;

public var NetCont:NetConnection;
public var NetStrem:NetStream
public var SharObj:SharedObject;

public function creationComplete():void{
connectBtn.label = "Connect";
connectBtn.addEventListener(MouseEvent.CLICK, ConnectServer);

sendBtn.label = "Send";
sendBtn.addEventListener(MouseEvent.CLICK, SendChat);
}

public function ConnectServer(event:MouseEvent):void{
NetCont = new NetConnection();
NetCont.client = new NetConnectionClient;
NetCont.connect(rtmpUrl.text);
NetCont.addEventListener(NetStatusEvent.NET_STATUS, createSharedObject);
}

public function createSharedObject(event:NetStatusEvent):void{

if(NetCont.connected){
SharObj = SharedObject.getRemote("SampleMessage",NetCont.uri,false,false);
SharObj.connect(NetCont);
SharObj.addEventListener(SyncEvent.SYNC, SharObjView);


}else{

Alert.show('Unable to Connect Internet or Rtmp Address');


}
}


public function SharObjView(event:SyncEvent):void{
msgBoard.htmlText += SharObj.data['SampleMessage']+"<br>";

}

public function SendChat(event:MouseEvent):void{
SharObj.setProperty("SampleMessage",enterMsg.text);
}

There are 2 optional for using SharedObject in ActionScript specially for flex SharedObject.getLocal() method or the SharedObject.getRemote()

What we use for internet connection is using getRemote. And here is code for next connection client :
package
{
public class NetConnectionClient
{
public function NetConnectionClient()
{
}
public function onBWDone(... rest):void
{

}
public function onBWCheck(... rest):uint
{
//have to return something, so returning anything :)
return 0;
}

public function onMetaData(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
}
}

No Response to "SharedObject in Sever Using NetConnection or by Remote"

 
powered by Blogger