By William B. Sanders
PDF Price: $19.99 USD
Cover | Table of Contents
C:\Program Files\Adobe \Flash Media Server 3\applications
→ Test Movie sequence with your application,
your server will be found and everything should work fine. However, if
you want to test your applications using a LAN or just using your
browser, you need to place them where they will be recognized by your
Web server using the HTTP protocol on your localhost (127.0.0.1) or
local LAN IP address. That is, all your HTML and SWF files need to be
placed in the Web server’s root directory. Because it’s easier to
develop and test applications, you also can place the FLA and AS files
in the same folders as the SWF and HTML files. shows a typical setup
on a Windows XP box using an Apache Web server.NetConnection instance. The basic
routine is as follows:nc = new NetConnection( );
nc.connect("rtmp:/appName");
nc.connect("rtmp:/FMSapp")
nc.connect("rtmp://www.myDomain.com/FMSapp")
→ All Programs → Adobe →
Flash Media Server 3 → Management
Console, as shown in .→ Clients option. When the application
successfully launches, you will see the name of the application, the
number of clients currently using the application, plus other information
about the client as shown in .
ObjectEncoding package. FMS2 (in case
you’re using it instead of FMS3) requires the NetConnection property defaultObjectEncoding to change the AMF default
from 3 to 0 using the following line:NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
defaultObjectEncoding
lines.RecordPlay and save the FLA file
again.package
{
import fl.controls.Button;
import fl.controls.TextInput;
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
import flash.events.Event;
//import flash.net.ObjectEncoding;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
public class RecordPlay extends MovieClip
{
private var nc:NetConnection;
private var ns:NetStream;
private var rtmpNow:String;
private var msg:Boolean;
private var cam:Camera;
private var mic:Microphone;
private var vid1:Video;
private var vid2:Video;
private var recordBtn:Button;
private var stopBtn:Button;
private var playBtn:Button;
private var textInput:TextInput;
private var metaSniffer:Object;
private var dur:Number;
function RecordPlay ()
{
//NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
nc=new NetConnection();
nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
rtmpNow="rtmp://192.168.0.11/vid2/recordings";
//rtmpNow="rtmp:/vid2/recordings";
nc.connect (rtmpNow);
addMedia ();
addUI ();
recordBtn.addEventListener (MouseEvent.CLICK,startRecord);
stopBtn.addEventListener (MouseEvent.CLICK,stopAll);
playBtn.addEventListener (MouseEvent.CLICK,startPlay);
}
private function checkConnect (e:NetStatusEvent):void
{
msg=(e.info.code=="NetConnection.Connect.Success");
if (msg)
{
ns = new NetStream(nc);
metaSniffer=new Object();
ns.client=metaSniffer;
metaSniffer.onMetaData=getMeta;
}
}
private function getMeta (mdata:Object):void
{
//Dummy to avoid error
}
private function addMedia ():void
{
cam=Camera.getCamera();
cam.setKeyFrameInterval (12);
cam.setMode (240,180,15);
cam.setQuality (0,80);
mic=Microphone.getMicrophone();
mic.rate=11;
videoSetup ();
}
private function videoSetup ():void
{
vid1=new Video(cam.width,cam.height);
vid1.attachCamera (cam);
vid1.x=100;
vid1.y=70;
addChild (vid1);
vid2=new Video(cam.width,cam.height);
vid2.x=vid1.x+vid1.width+10;
vid2.y=vid1.y;
addChild (vid2);
}
private function addUI ():void
{
recordBtn=new Button();
recordBtn.label="Record";
recordBtn.x=100;
recordBtn.y=70+(cam.height) +5;
recordBtn.width=70;
addChild (recordBtn);
stopBtn=new Button();
stopBtn.label="Stop";
stopBtn.x=recordBtn.x+100;
stopBtn.y=recordBtn.y;
stopBtn.width=60;
addChild (stopBtn);
playBtn=new Button();
playBtn.label="Play";
playBtn.x=stopBtn.x+85;
playBtn.y=recordBtn.y;
playBtn.width=60;
addChild (playBtn);
textInput=new TextInput();
textInput.x=recordBtn.x;
textInput.y=recordBtn.y + 30;
addChild (textInput);
}
private function startRecord (e:Event):void
{
if (ns)
{
recordBtn.label="Recording";
ns.attachAudio (mic);
ns.attachCamera (cam);
ns.publish (textInput.text,"record");
}
}
private function stopAll (e:Event):void
{
playBtn.label="Play";
recordBtn.label="Record";
ns.close ();
}
private function startPlay (e:Event):void
{
if (ns)
{
playBtn.label="Playing";
vid2.attachNetStream (ns);
ns.play (textInput.text);
}
}
}
}
get( ) method. The parameters for both
Camera.getCamera( ) and Microphone.getMicrophone( ) refer to the
drivers in one’s local system. Usually, the process is nothing more than
using the instantiating process without any parameters, such as,get( ) method. The parameters for both
Camera.getCamera( ) and Microphone.getMicrophone( ) refer to the
drivers in one’s local system. Usually, the process is nothing more than
using the instantiating process without any parameters, such as,NetStream instance
to stream video to the server where it will be streamed back to view
the video object.
video.width=camera.width; video.height=camera.height
package
{
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.media.Video;
public class FMElive extends Sprite
{
private var good:Boolean;
private var vid:Video;
private var nc:NetConnection;
private var ns:NetStream;
private var rtmpNow:String;
private var metaSniffer:Object;
public function FMElive()
{
setVid();
rtmpNow="rtmp://192.168.0.11/fme/viewer";
nc=new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, checkConnect);
nc.connect(rtmpNow);
}
private function getMeta (mdata:Object):void
{
//Live
}
private function checkConnect(e:NetStatusEvent):void
{
good=(e.info.code=="NetConnection.Connect.Success");
if(good)
{
ns=new NetStream(nc);
vid.attachNetStream(ns);
ns.play("liveFME");
metaCheck();
}
}
private function setVid():void
{
vid=new Video();
vid.x=95;vid.y=80;
vid.width=360,vid.height=240;
addChild(vid);
}
private function metaCheck():void
{
metaSniffer=new Object();
ns.client=metaSniffer;
metaSniffer.onMetaData=getMeta;
}
}
}
private var so:SharedObject;
new
statement, the getRemote() method
creates the remote shared object. Using the same data type (SharedObject), you can also create a local
shared object with the method, getLocal(). Given the focus on FMS3, you will
not find any examples using local shared objects in this book.SharedObject.setProperty() method to assign
values to a shared object property. By assigning different shared object
properties you can create slots using most kinds of data types. The
following shows a simple property slot:var memberName:String= name_txt.text;
so.setProperty("cliName", memberName);
cliName. So it now has a storage slot for a
string name that can be shared with others connected to the same
application. In the same way, you can set up as many slots as your
application needs, using the appropriate data type for the data to be
stored. Whenever the shared object property changes, it fires a package
{
import flash.display.Sprite;
import flash.net.SharedObject;
import flash.events.NetStatusEvent;
import flash.events.SyncEvent;
import flash.net.NetConnection;
import flash.events.MouseEvent;
//import flash.net.ObjectEncoding;
public class MinSOmc extends Sprite
{
private var pointer_so:SharedObject;
private var nc:NetConnection;
private var good:Boolean;
private var island:Island;
public function MinSOmc()
{
//NetConnection.defaultObjectEncoding=flash.net.ObjectEncoding.AMF0;
//Connect
var rtmpNow:String="rtmp://192.168.0.11/basicSO";
nc=new NetConnection ;
nc.connect (rtmpNow);
nc.addEventListener (NetStatusEvent.NET_STATUS,doSO);
island=new Island ;
addChild (island);
island.x=200;
island.y=200;
island.addEventListener (MouseEvent.MOUSE_DOWN,beginDrag);
island.addEventListener (MouseEvent.MOUSE_UP,endDrag);
}
private function doSO (e:NetStatusEvent):void
{
good=e.info.code == "NetConnection.Connect.Success";
if (good)
{
//Shared object
pointer_so=SharedObject.getRemote("point",nc.uri,false);
pointer_so.connect (nc);
pointer_so.addEventListener (SyncEvent.SYNC,doUpdate);
}
}
private function doUpdate (se:SyncEvent):void
{
for (var cl:uint; cl < se.changeList.length; cl++)
{
trace(se.changeList[cl].code);
if (se.changeList[cl].code == "change")
{
switch (se.changeList[cl].name)
{
case "xpos" :
island.x=pointer_so.data.xpos;
break;
case "ypos" :
island.y=pointer_so.data.ypos;
break;
}
}
}
}
private function beginDrag (e:MouseEvent)
{
island.addEventListener (MouseEvent.MOUSE_MOVE,moveMc);
island.startDrag ();
}
private function endDrag (e:MouseEvent)
{
island.stopDrag ();
}
private function moveMc (e:MouseEvent)
{
e.updateAfterEvent ();
pointer_so.setProperty ("xpos",island.x);
pointer_so.setProperty ("ypos",island.y);
}
}
}