background image

78

Debugging and Monitoring Applications

About the System.onStatus handler

In addition to the specific 

onStatus

 methods provided for the classes listed in 

“About 

onStatus event handlers” on page 76

, Flash  also provides a “super handler” called 

System.onStatus

. If 

onStatus

 is invoked for a particular object with a level property of 

Error

 and no function is assigned to respond to it, Flash processes a function assigned to 

System.onStatus

 if it exists. 

The following code example sends a message to the Output panel when an error message 
occurs for an object that hasn’t been assigned an 

onStatus

 handler:

System.onStatus = function(genericError) {

// Your script would do something more meaningful here.
trace("An error has occurred. Please try again.");

}

About debugging a 
NetConnection.Connect.Failed message

If a 

NetConnection.connect()

 command returns an information object with a 

code

 value 

of 

NetConnection.Connect.Failed

, you cannot establish a connection with the server. 

Every time you receive this error, ask yourself some standard troubleshooting questions:

Are you connecting to the correct server?

Is the server running?

Are you specifying the protocol (rtmp:) for connecting to the server? 

If you are connecting from behind a firewall, are you specifying the correct protocol 
(rtmpt:)?

Attempts to connect to the server can also fail if the permissible number of socket connections 
on either the client or the server computer is at its limit. This limit is dependent on how much 
physical memory your server has, and how busy the connections are. On Windows systems, 
the memory for socket connections is allocated out of the non-paged memory, so it cannot be 
swapped out to a page file. You may see that you reach the maximum limit at different values 
from time to time as other running programs (such as core operating-system services) are 
competing with your program for space in the non-paged memory pool.

Summary of Contents for FLASH MEDIA SERVER 2-DEVELOPING MEDIA

Page 1: ...Developing Media Applications ...

Page 2: ...n of the link does not imply that Macromedia endorses or accepts any responsibility for the content on those third party sites Jabber is a registered trademark of the Jabber Software Foundation Sorenson Spark video compression and decompression technology licensed from Sorenson Media Inc Copyright 2002 2005 Macromedia Inc All rights reserved This manual may not be copied photocopied reproduced tra...

Page 3: ...erver side and client side files 15 Storing your application s server side script files 16 About application instances 17 File types used by Flash Media Server 18 Connecting to the server 19 Starting the service 19 Opening a connection to the server 20 Chapter 2 Flash Media Server Architecture 21 Understanding the Flash Media Server architecture 22 About streams and shared objects 23 About connect...

Page 4: ...48 Avoiding audio feedback 48 Keeping the microphone on 48 The NetConnection class client side 49 The NetStream class 50 Using multiple data types in a stream 50 Getting the stream time length with ActionScript 50 About buffering a stream 51 About the play status of a stream 51 The SharedObject class 52 About synchronizing shared objects 52 Using shared object slots effectively 52 Flushing remote ...

Page 5: ...6 Application Development Tips and Tricks 81 About file types and paths 81 About shared object files 82 Portability across servers 83 Client server script interdependence 84 Using multiple script files 85 Archiving and compiling server side script files 86 Compiling scripts to bytecode 89 Forcing the Player Settings panel to appear 91 Managing bandwidth 92 Writing double byte applications 93 About...

Page 6: ...6 ...

Page 7: ...cross networks for delivery to the Internet FMS is part of the Macromedia complete solution for database connectivity directory systems and presence services and is the only server that can deliver audio and video to the popular Flash Player Intended audience This manual shows you the Flash developer the steps involved in setting up a development environment and creating Flash Media Server applica...

Page 8: ...Server and the new features in version 2 Also included are system requirements and installation instructions You can find a printed version of this manual in the Flash Media Server CD case This manual Developing Media Applications explains how to set up your development environment and how to use the Flash authoring environment and the Flash Media Server application programming interface API to cr...

Page 9: ...ird party resources on Flash Media Server including the following Macromedia Flash community sites Macromedia Flash books Object oriented programming concepts Typographical conventions The following typographical conventions are used in this manual Code font indicates ActionScript statements and literal text used in examples Code font italic indicates placeholder elements in code For example attac...

Page 10: ...10 About This Manual ...

Page 11: ...a Server applications you must install the Macromedia Flash authoring software Flash Media Server and the latest Flash Player To write applications that capture audio or video you also need to install a microphone or camera Additionally if your application requires server side scripts for your Flash Media Server applications you ll need a UTF 8 JavaScript editor such as the Script window in Flash ...

Page 12: ...context menu click the Microphone or Camera panel and select your preferred device from the pop up menu Using a JavaScript editor You can use any text editor to write server side ActionScript code which you ll store in files with an extension of asc or js You may prefer to use software specifically designed for writing web based applications such as Flash Professional or Dreamweaver To create an a...

Page 13: ...e ActionScript code should be attached to a layer on the first keyframe of your FLA file not to individual objects Client side code in files published for Flash Player 7 or later is case sensitive Writing server side ActionScript code For applications that use server side ActionScript code place the code in a server side script file Name the file main asc or it can have a name such as registered_a...

Page 14: ...ct a name for your new application for example my_app and register the application with the server in the Flash Media Server applications directory create a new directory with the name of your application This name is your registered application name The directory is your registered application directory 2 In Flash create a FLA file that includes a new NetConnection statement with the registered a...

Page 15: ...to find and also explains how and why to run application instances Storing server side and client side files The default location for server side application files is C Program files Macromedia Flash Media Server 2 applications on Windows or opt macromedia fms applications on UNIX This location is referred to as the applications directory When you create a media application you must create a regis...

Page 16: ...eate the server side script file for your application in the Flash ActionScript editor or in a JavaScript text editor Name the script file main asc or main js or registered_app_name asc or registered_app_name js where registered_app_name is the name of the registered application directory and the application itself Save the script file in your registered application directory For example if you ha...

Page 17: ...room_01 my_nc connect rtmp myServer myDomain com chatApp room_02 Each application instance is uniquely named Unlike the parent application an instance does not require that its own directory be defined on the server However application resources such as streams and shared objects are independent for each instance and are stored in their own directories under the streams and sharedObjects storage d...

Page 18: ...Flash Media Server uses or creates the following file types ASC and JS files Server side script files that you write or that are provided with Flash Media Server When you create server side scripts use the Flash ActionScript editor or a JavaScript editor and place the scripts in the subdirectory you create for your application in your registered application directory for example applications chat_...

Page 19: ...ecting to the server To connect to an instance of Flash Media Server you first start the service and then issue new NetConnection and NetConnection connect commands in your client side script These tasks are discussed in this section Starting the service If the server is not already started you can start it manually From the Windows Start menu select Programs Macromedia Macromedia Flash Media Serv...

Page 20: ...er rtmp host port appName instanceName To connect to a virtual host other than the default virtual host specify the virtual host s name in host If the server is running on your local computer you can use localhost as the host name in the URI this is often convenient during application development For example the following code uses the new NetConnection constructor to create a new connection objec...

Page 21: ...sist of a client Macromedia Flash application SWF file that is run by Flash Player and a server component that communicates with the client The server component consists minimally of an application folder you ve created on the server that is running Flash Media Server This folder can optionally contain server side ActionScript ASC files and other resource files that the media application uses ...

Page 22: ...sage Protocol RTMP In a typical scenario a web server delivers the Flash client to Flash Player over HTTP The Flash client then uses RTMP to establish a persistent connection to Flash Media Server allowing for an uninterrupted data stream to flow between client and server Web server Sends SWF HTTP 1 Client Plays SWF using Flash Player RTMP 2 Flash Media Server Sends receives data stream 3 ...

Page 23: ...ia Server to implement transactions its core use is handling interactions coordinating the actions of multiple connected users or clients and transmitting server side data Flash Media Server provides two communication models that simplify the process of handling user interactions streams and shared objects Understanding streams Streams are a time based flow of synchronized audio video and or data ...

Page 24: ...files from existing digital video or audio files by using third party video encoding utilities like On2 or Sorenson Squeeze or export them from Flash In this way you can use the Flash Media Server to stream prerecorded content Live stream Playback of a stream recorded as a FlashVideo FLV file NetStream object SERVER Client publishes Players NetStream object FLV SERVER Players ...

Page 25: ...cts which have the file and provides messaging data synchronization and data storage services Flash clients connect or subscribe to a remote shared object and receive updates whenever a change is made to that shared object Also messages can be sent to all clients connected to a remote shared object A remote shared object can persist across application sessions or be temporary Shared objects provid...

Page 26: ...ces see About Flash Media Server classes on page 37 Flash Media Server interacts with external data sources Macromedia Flash Remoting is a gateway that connects your media application to J2EE application servers and Microsoft Windows NET servers You can connect to Flash Remoting from a client side or server side script Flash Remoting relies on its own ActionScript library called NetServices to lin...

Page 27: ...ing real time interactions among multiple users or communicate with external resources if necessary You can write ASC files in Flash Professional a text editor or a JavaScript editor For information on server side ActionScript see the Server Side ActionScript Language Reference To deploy an application the client and server files need to be published to their proper locations For applications depl...

Page 28: ...egistered application directory you ve defined on the server For more information on registering an application directory see Chapter 1 Getting Started Web server directory HTML swf HTML SWF FILE Flash logic ActionScript swf swf HTML FILE HTML HTML wrapper ht ml ASC FILE Server logic Server side ActionScript asc Flash Media Server application directory asc flv ...

Page 29: ...e server the server loads the application and creates the application instance if it isn t already running The server accepts the connection creates a new server side Client object to represent the client application on the server and executes any server side scripts that you provide The server side Client object corresponds to the client side NetConnection object that was used to connect to the s...

Page 30: ...sconnect handler is called When the application is unloaded onAppStop is invoked To accept the connection in the onConnect handler return true or call application acceptConnection to reject the connection return false or call application rejectConnection If true or false are not returned in the onConnect handler clients remain pending until acceptConnection or rejectConnection is called Connection...

Page 31: ... example of this see the Client class entry in the Server Side ActionScript Language Reference A Flash application can then use the NetConnection call method to call the remotely defined method and optionally specify a callback object to handle the result that the server returns On the server the method corresponding to the client call is invoked and a result is returned to the client The followin...

Page 32: ... stream that is already being published by someone else NetStream Failed Error An attempt to use a Stream method failed NetStream Unpublish Success Status An attempt to unpublish was successful NetStream Record Start Status Recording was started NetStream Record NoAccess Error An attempt was made to record a read only stream NetStream Record Stop Status Recording was stopped NetStream Record Faile...

Page 33: ...server side script can optionally specify a result handler object Again the client can return a result and the server s onResult handler is called on the callback object sent to the client Call flow from server to client with result passed back to server The following table lists Flash Media Server Status Messages Code Level Meaning NetStream Clear Success Status A recorded stream was deleted succ...

Page 34: ...connect the remote shared object to the server Calling SharedObject connect associates the SharedObject with the NetConnection object which is the connection used for sending and receiving data to and from the server so the shared object can send and receive updates to and from the server NetStream Record NoAccess Error An attempt was made to record a read only stream NetStream Record Stop Status ...

Page 35: ...ly modified the contents of the shared object For a complete list of codes and their descriptions see the SharedObject onSync entry in the Client Side ActionScript Language Reference for Flash Media Server 2 The following diagram illustrates a scenario in which two clients Client 1 and Client 2 connect to the same remote shared object obj1 When each client first connects to the shared object a cle...

Page 36: ...36 Flash Media Server Architecture ...

Page 37: ...sses Camera Microphone NetConnection NetStream SharedObject and Video For more information on using these classes see the Client Side ActionScript Language Reference for Flash Media Server 2 The server side API provides the following classes Application Client File LoadVars NetConnection SharedObject Stream WebService XML XMLSocket XMLStreams For more information on using these classes see the Ser...

Page 38: ...ion server but this chapter focuses on using the NetConnection class to communicate with Flash Media Server NetStream class The client side NetStream class opens a one way streaming connection between Flash Player and Flash Media Server through a connection made available by a client side NetConnection object A NetStream object is like a channel inside a NetConnection this channel can either publi...

Page 39: ... NetConnection call command and can invoke methods of the client side NetConnection object You can use the properties of a Client object to determine the version platform and IP address of each client Using the Client class you can also set individual read and write permissions of various application resources such as Stream objects and SharedObject objects For more information see Implementing dy...

Page 40: ...The following server side classes are used in tandem with the WebService class the Log class the SOAPFault class and the SOAPCall class XML class The server side XML class lets you load parse send build and manipulate XML document trees XMLSocket class The server side XMLSocket class implements client sockets that let the Flash Player communicate with a server identified by an IP address or domain...

Page 41: ...end user s computer and may be accessed at different times by one or more Flash applications Local shared objects can also be non persistent that is available only while the application is running Local shared objects don t require a connection to the Flash Media Server and are not discussed in detail in this manual For information about where persistent local shared object data is stored see Abou...

Page 42: ...ared object files on page 82 For more information about remote shared objects see the SharedObject getRemote entry in the Client Side ActionScript Language Reference for Flash Media Server 2 About proxied shared objects A proxied shared object is a remote shared object that instead of being shared between a client and server application is shared between two different Flash Media Server applicatio...

Page 43: ...Connect handler is a good approach when you want to set up different methods based on user login information However if you want to set up a method that is available to all clients you can use the ActionScript 1 0 prototype property of the Client object as in the following example A user has connected application onConnect function newClient userName if userName admin newClient adminFunc function ...

Page 44: ...equence of actions application onConnect function clientObj name passwd First accept the connection application acceptConnection clientObj After client is registered with the application instance you can use call method clientObj call onWelcome You are now connected return After you call acceptConnection or rejectConnection within onConnect return value is ignored T I P If you re using components ...

Page 45: ... side you would have the following application onConnect function newClient name newClient name name return true application onDisconnect function client for var i 0 i application clients length i application clients i call userDisconnects client name On the client side you would have the following nc new NetConnection nc userDisconnects function name trace name quits nc connect rtmp app_name user...

Page 46: ...ch component can have its own application onConnect handler By using onConnectAccept and onConnectReject you can customize a component or create a new one to implement authentication for example the code in a component could query a database and decide to accept or reject a user based on the user name and password stored in the database For more information about application onConnectAccept and ap...

Page 47: ...era cannot be shared between applications running in two different processes for example one in the browser and one in a stand alone player The Client class When attaching methods to a Client object in server side scripts remember that all methods on the client object can be called by a script in the SWF file on the client You should not include any methods on the Client object that you would not ...

Page 48: ... too much echo from your speakers Because echo suppression removes only a portion of the output signal from the user s input you might still experience feedback if your microphone is too close to your speaker To avoid feedback try following these guidelines Lower your speaker volume Move the microphone and speakers farther apart Troubleshoot your hardware setup for proper installation and settings...

Page 49: ...s applicable only if Flash Media Server and the web server are running on the same machine To do so leave off the second slash in targetURI For example the following commands will instruct Flash Player to connect to the same host and domain as the web server the SWF file was served from nc new NetConnection nc connect rtmp myApp Another way to avoid the security problem is to use a bit of JavaScri...

Page 50: ...ith ActionScript If you are buffering your streams you can use the NetStream bufferLength property to get the number of seconds currently in the buffer Sometimes however you may want to get the total length of a stream Flash Player doesn t have this information but Flash Media Server does the server has a Stream length property that the client can request through a message to the server You can us...

Page 51: ... outgoing queue can grow before Flash Player considers dropping messages to determine how much data is currently in the queue use NetStream bufferLength For a fast connection the value returned by NetStream bufferLength will never approach the value of NetStream bufferTime but on a slow connection it might Therefore if you know your application is running over a slow connection and you want to min...

Page 52: ...mote shared object that is persistent locally or on the server In the latter case all the object properties are set to empty strings and SharedObject onSync is invoked with the value of the code property set to clear Then SharedObject onSync is invoked again this time with the value of code set to change and the properties of the client s instance of the remote shared object will be set to match t...

Page 53: ...he local copy of the shared object To manually flush the server copy of the shared object you must call SharedObject flush in a server side script as follows Sample server side code for flushing a persistent shared object to the server Get the shared object when the application is loaded application onAppStart function application mySO SharedObject get SharedObjName true When a user disconnects fl...

Page 54: ...of whether it was the most recent high score or any score currently coming in from all other clients If you lock and unlock the shared object used to store the highest score you can compare each score sequentially and thus ensure that no comparison is lost application onAppStart function application scoreSO SharedObject get high_score_so true application scoreSO onSync function listVal trace got a...

Page 55: ...you must use server side code like the following s Stream get foo if s s clear The System class Macromedia Flash Media Server sends text in UTF 8 format If you set the System useCodepage to a value of true in your ActionScript code your media application might not work properly A value of true causes Flash Player to treat all text based on the end user s code page as in early versions of Flash Pla...

Page 56: ...deo objects dynamically using the duplicateMovieClip and removeMovieClip methods Understanding frame rates If you embed an FLV file in a Flash application in a static SWF file its frame rate will be the same as the frame s playback rate in the timeline When you stream the data in an FLV the video played through Flash Media Server can have a different frame rate than the SWF that contains it For ex...

Page 57: ... treat clients as individuals You can deliver streams based on Flash Player version With a little extra code you can also deliver streams based on client bandwidth About creating live web events Flash Media Server application clients can publish a live video stream to the server and multiple clients can subscribe to the broadcast This lets you create live web events If you need to hold a large liv...

Page 58: ...of the client s Flash Player version In the vhost xml configuration file you can map the keys to the directories in the VirtualKeys and VirtualDirectory sections of the file to deliver custom content for individual clients For customizing stream delivery based on bandwidth you must check the client bandwidth in a script and change the client keys accordingly You can set the key and directory value...

Page 59: ... WIN 7 0 19 0 to WIN 9 0 0 0 A Key Key from WIN 6 0 0 0 to WIN 7 0 18 0 B Key Key from MAC 6 0 0 0 to MAC 7 0 55 0 B Key VirtualKeys VirtualDirectory Streams key A foo c streams on2 Streams Streams key B foo c streams sorenson Streams Streams key foo c streams Streams VirtualDirectory For more information about editing the Key and Streams tags see Vhost xml file in Managing Flash Media Server Deli...

Page 60: ...ms key fp8slow foo c streams Vp622k Streams Streams key fp8medium foo c streams Vp6150k Streams Streams key fp8fast foo c streams Vp6300k Streams Streams key foo c streams Streams VirtualDirectory In your server side script in the application onConnect handler write a bandwidth detection routine and append the range to the value of each client s virtual key as in the following example client virtu...

Page 61: ...ent Flash Player versions use the same virtual path with different physical directories for each Streams tag as in the following example VirtualDirectory Specifies virtual directory mapping for recorded streams To specify multiple virtual directory mappings for a stream add additional Streams tags one for each virtual dir mapping Syntax for virtual directories is as follows Streams foo c data Stre...

Page 62: ...he virtual directory and the MP3 file you want to play For information on virtual directories and the Streams tag see Registering client applications in Managing Flash Media Server To play MP3 files attach a NetStream object to a Video object and call the play method or attach it to the MovieClip object and call the attachAudio method In the parameter that specifies streamname or what to play you ...

Page 63: ...ded Controlling MP3 files with server side ActionScript You can use methods of the server side Stream object to play back an MP3 file Stream play and get the length of an MP3 file Stream length For more information on using these methods with MP3 files see the Stream play and Stream length entries in the Server Side ActionScript Language Reference To delete MP3 files using server side ActionScript...

Page 64: ...er stream application myStream Stream get description application myStream onId3 function info for i in info trace i info i if application myStream Publish the ID3 text tag data of bolero mp3 to a stream description Use the id3 prefix in front of the stream name and specify 0 for the startTime parameter application myStream play id3 bolero 0 1 ...

Page 65: ...ation instance on the server A list of clients connected to the application instance A list of active shared objects for the application instance A list of active streams for the application instance Information about the overall state of the selected application instance such as total uptime or number of users For example a designer debugging an application wants to view the content of a particul...

Page 66: ... a computer where Flash Player is installed 2 Type the name of the server into the Server Name text field or use the pop up menu to select the name of any server that is connected successfully The server name is an identifier for your own use so you can name a server any name you want 3 Type the server URL in the Server Address text field or type localhost if the server and the management console ...

Page 67: ... the View Applications panel to view load and unload application instances TI P The initial screen of the management console also has numerous links to Flash Media Server resources such as the Developer Center Support Center release notes documentation and online help T I P The light icon to the right of the help button question mark indicates whether the management console is connected to a serve...

Page 68: ... Name To sort by client click the Clients column header To disconnect the management console from the server click Logoff You return to the log on screen see Connecting the management console to a server on page 66 Changing or pausing the refresh rate The information in the management console panels refreshes at a default rate of every 5 seconds You can change the refresh rate to any time interval...

Page 69: ...string type the string or a portion of it into the Find text box and click Find Next You can continue to click Find Next to find each instance of your search string To view a string that appears earlier in the log click Find Previous To delete all messages in the log click Clear Log To reload the application instance for example if you changed one of the server side scripts that the application us...

Page 70: ...tes the connection protocol that the client uses such as RTMP Bytes In and Bytes Out indicates the average bytes per second being sent to and from the server The management console calculates this ratio by dividing the total number of bytes received in the most recent 15 seconds and dividing that value by 15 When the panel first appears these figures appear as pending because there is only one dat...

Page 71: ...cation uses or to disconnect all users click Reload this application small button to the right of the panel names To remove the application instance click Unload this application small button to the right of the panel names To disconnect the management console from the server click Logoff To view a different panel click the corresponding panel name Live Log Shared Objects Streams or Performance Ab...

Page 72: ...he data properties assigned to the shared object For more information see the SharedObject resyncDepth entry in the Server Side Media ActionScript Language Reference The Shared Objects panel lets you perform the following tasks To customize this panel click the pop up menu in the far right column of the left table and select or deselect the columns to display To obtain data from shared objects you...

Page 73: ...an entry displays the live stream name For a recorded steam an entry displays the flv mp3 file name for example flv stream2 flv or mp3 sound mp3 If a client requests the stream2 flv there will be two entries one for flv stream2 flv stored and one for the actual netstream going to the client that the netstream ID names and of type NetStream Type indicates a server provided string that describes wha...

Page 74: ...r side scripts that the application uses or to disconnect all users click Reload this application small button to the right of the panel names To remove the application instance click Unload this application small button to the right of the panel names To disconnect the management console from the server click Logoff To view a different panel click the corresponding panel name Live Log Clients Sha...

Page 75: ...anel first appears these figures appear as pending because there is only one data point to start with figures appear after the panel is open for 15 seconds Active Connections indicates the number of users currently connected to the application instance Bandwidth indicates the amount of data that the application instance manages including data sent data received and the combined amount of data traf...

Page 76: ...button named Close Debug appears that you can click to close the connection About onStatus event handlers The client side Camera Microphone NetConnection NetStream and SharedObject classes as well as the server side Application NetConnection Stream and SharedObject classes provide an onStatus event handler that uses an information object to provide information status or error messages To respond t...

Page 77: ...st if the onStatus handler is not yet set up About overriding the onStatus handler Even if you don t need to do anything in the onStatus handler it s a good idea to override the generic onStatus handler whenever you create an object as shown in the following example Create function to trace all the status info function traceStatus info trace Level info level Code info code Assign this function to ...

Page 78: ...nformation object with a code value of NetConnection Connect Failed you cannot establish a connection with the server Every time you receive this error ask yourself some standard troubleshooting questions Are you connecting to the correct server Is the server running Are you specifying the protocol rtmp for connecting to the server If you are connecting from behind a firewall are you specifying th...

Page 79: ...he properties of an object 79 Tracing the properties of an object To find out why you might be having problems with a particular object you can iterate its properties as follows for i in my_obj trace i my_obj i ...

Page 80: ...80 Debugging and Monitoring Applications ...

Page 81: ...streams directory with application instance subdirectories For example if the application instance ChatApp MondayChat records a stream named chat the chat flv file is stored in the following location applications ChatApp streams MondayChat If you run an instance of ChatApp called TuesdayChat its files are stored in applications ChatApp streams TuesdayChat To play back an FLV file that was created ...

Page 82: ...41 Local shared objects are always persistent on the client up to available memory and disk space However by default Flash can save locally persistent remote shared objects only up to 100 K in size When you try to save a larger object Flash Player displays a Local Storage dialog box which lets the user allow or deny local storage for the domain that is requesting access The user can also use this ...

Page 83: ...ecifying a partial path for the location of a locally persistent remote shared object you can let several applications from the same domain access the same shared objects For more information see SharedObject getRemote in the Client Side ActionScript Language Reference for Flash Media Server 2 Portability across servers It is important to consider your development configuration and your production...

Page 84: ...computer as the Flash Media Server an absolute path is required and must be edited if files are moved at production time Client server script interdependence Because the client side and server side ActionScript code are part of the same application they must work interdependently One example of the interdependency between the client and server code is the server side ActionScript call method which...

Page 85: ...er code that the client can call must be a property of a server side Client object Using multiple script files As your application increases in complexity don t try to use a single script to do everything break your functionality up into multiple scripts each of which provides a specific set of functionality If you do use more than one file you can use a once only inclusion definition to optimize ...

Page 86: ...ent You can also use the archive compiler utility called FAR to compile server side script files to bytecode with the file extension ase to speed up the time required to load an application instance Archiving server side scripts A large application can contain multiple server side script files stored in different locations Some files are located in the application directory and others are scattere...

Page 87: ...main far or appname far file in the application folder If no FAR file is found the server looks for the main script in the application folder When scripts in the FAR file refer to other script files in a scriptlib path Macromedia recommends that you place all of the required script files from the path into the FAR file This placement prevents an application from loading a different version of the ...

Page 88: ... script library directory installdir scriptlib The testFAR developer isn t sure where the applications are going to be deployed so they include all of the ASC files inside the webServices folder so that the main script can always find the web services When the WebServices asc file is loaded from the main script load webServices WebServices asc is called It is important to maintain the same hierarc...

Page 89: ...Flash Media Server installation directory In this case the FAR file acts like a directory instead of looking for script files from a directory Flash Media Server looks for the script files in the FAR file The scriptlib is defined in the fcs ini file as in the following example APP JS_SCRIPTLIBPATH C Program Files Macromedia Flash Communication Server MX scriptlib To include a FAR file in the scrip...

Page 90: ...to the fms_version field of the 36 byte header If unspecified this defaults to 1 6 This option is also added as an optional header that looks like fcsver 1 6 n Note This option adds content to the ASE file but the Flash Media Server does not use the content at this time e date Optional Specifies the expiration date of this file The date is specified as mm dd yyyy After this date the file is no lon...

Page 91: ...ttings 2 Opens the Camera panel System ShowSettings 3 For example if your application requires the use of a camera you can inform the user that they must select Allow in the Privacy Settings panel and then issue a System showSettings 0 command Make sure your Stage size is at least 215 by 138 pixels this is the minimum size that Flash requires to display the panel For more information see the Syste...

Page 92: ...ed when a status is changed or an error is posted in the NetStream A status message NetStream Play InsufficientBW shows that data playing through the NetStream is slower than the normal speed Data can be slower than normal speed for many reasons For example the client can have insufficient bandwidth or the server can be busy and not send data at the expected rate The status message NetStream Play ...

Page 93: ...such as Date toLocaleString which converts the string to the locale encoding for that system To ensure UTF 8 encoding in Dreamweaver you need to check two settings the document encoding setting and the inline input setting To change the document encoding setting select Modify Page Properties then select Document Encoding Choose Unicode UTF 8 To change the inline input setting select Edit Preferenc...

Page 94: ... a mechanism to implement dynamic access control list ACL functionality for shared objects and streams By default all connections have full access to all streams and shared objects You can control who has access to create read or update shared objects or streams Every connection to a server side application instance is represented by a Client object on the server side and each Client object has tw...

Page 95: ...rity of your applications and the data they use Using SSL SSL support is available in Flash Media Server 2 To use SSL you need to obtain an SSL certificate from a certificate authority or create a certificate yourself Flash Media Server supports both incoming and outgoing SSL connections To use SSL in your applications you need to configure both your applications and Flash Media Server settings Fo...

Page 96: ...cedures to be aware of include writing to the hard disk without checking the quantity of data being written procedures that can be infinitely looped and so on If you are integrating third party code you must also protect your application against malice and bugs For more information see Protecting scripts from third party code on page 96 Protecting scripts from third party code Flash Media Server h...

Page 97: ...nd evaluated no other application scripts are loaded After the secure asc file is loaded the server switches to normal script execution mode until the application is unloaded In secure script execution mode the global getGlobal and protectObject functions are available These functions let you create system objects In normal script execution mode the rest of the server side scripts are loaded and e...

Page 98: ...re asc var global getGlobal Grab the global object var idgen idgen _nextID 0 idgen nextID function return this _nextID Create a protected object out of idgen and make it available globally as idGen global idGen protectObject idgen Make idGen non enumerable read only and permanent setAttributes global idGen false true true The following is the main asc file that attempts to access the idGen variabl...

Page 99: ... globally Also set its attributes so that it is read only and not deletable global system protectObject sysobj setAttributes global system false true true Now add a global load function for compatibility Make it read only and non deletable global load function path return system load path setAttributes global load false true true Asynchronous system calls An asynchronous call returns immediately b...

Page 100: ...chronous system calls where the caller is unprivileged and relies on a system call to set up and complete the asynchronous call however the callback must continue to be unprivileged This implementation is useful for example if a system object is trying to wrap and hide a net connection as in the following The following code is in a secure asc file sysobj remoteCall function func responder arg1 arg...

Page 101: ... Variable or property userName Begin function names and variables with a lowercase letter Capitalize objects and object constructors Use mixed case uppercase and lowercase when you name variables although other formats are acceptable as long as they are used consistently within the application Variable names can contain only letters numbers and underscores However do not begin variable names with ...

Page 102: ...perating system such as UNIX Remember that these syntax recommendations are guidelines Most importantly choose a naming scheme and use it consistently Naming variables to support code hinting The Macromedia Flash ActionScript editor has built in code hinting support To take advantage of this you can either use strict typing syntax for the variables new in ActionScript 2 0 or use a specific format ...

Page 103: ...This makes it easier for them to address that issue The following is an example of a simple comment for a variable var clicks Number 0 variable for number of button clicks Block comments are useful when a comment contains a large amount of text Initialize the clicks variable that keeps track of the number of times the button was clicked Some common methods for indicating specific topics are TODO t...

Page 104: ...l local variables should use the keyword var This prevents variables from being accessed globally and more importantly prevents variables from being inadvertently overwritten Using var also lets you use strict typing for an object for type checking at compile time For more information on strict typing search for strict data typing in Flash Help For example the following code does not use the keywo...

Page 105: ...rwritten by the counter variable within the function The following is the corrected code which uses the keyword counter to declare both of the variables var counter 7 function loopTest trace counter for var counter 0 counter 5 counter trace counter trace counter loopTest trace counter ...

Page 106: ...106 Application Development Tips and Tricks ...

Page 107: ...r 46 application onDisconnect handler 45 application rejectConnection method 77 applications accepting connections 46 active connections viewing 75 and instance names 15 and your registered application directory 14 bytes per second 75 cameras using in 47 checklists for creating 14 client server communication 84 clients viewing connected 75 commenting code 103 connecting to the server 43 CPU and me...

Page 108: ...o class 38 56 WebService class 40 XML class 40 XMLSocket class 40 XMLStreams class 40 Client class about 39 and client side NetConnection object 84 call method 44 readAccess property 94 receiving messages from the client 39 setBandwidthLimit method 92 tips and tricks 47 virtualKey property 58 writeAccess property 94 client server communication 84 object communication 31 workflow 29 client side Act...

Page 109: ...l in client side ActionScript 86 including external in server side ActionScript 86 lowercase names using 83 multiple using 85 files naming 83 Flash authoring tool 11 Flash Media Server architecture 21 classes See classes communication models 23 connecting to 19 online forum 9 release notes 9 support for learning about 9 third party resources 9 tips and tricks 81 Flash Player 11 Flash Player Settin...

Page 110: ...uppression method 48 Microphone setSilenceLevel method 48 Microphone useEchoSuppression method 48 MP3 files about 62 controlling with ActionScript 63 ID3 tags 63 publishing 63 multiple files using 85 N NetConnection class client side about 38 call method 39 constructor 20 security issues 49 NetConnection class server side 39 NetConnection object client side and Client object 84 NetConnection call ...

Page 111: ...d Objects panel 72 properties getting object 79 protectObject method 97 R read write access shared objects 94 recorded streams avoiding collisions 17 deleting files 55 files for 81 refresh rate See management console registered application directory 14 registered application name 14 relational databases 26 release notes for Flash Media Server 9 remote shared objects See shared objects remote remov...

Page 112: ... method 83 SharedObject getLocal method 82 SharedObject getRemote method 18 34 52 83 SharedObject onSync handler 52 55 SharedObject resyncDepth method 72 SharedObject send method SharedObject class send method 55 slots See shared objects SOL and SOR files 19 Sorenson H263 codec 58 SSL Secure Sockets Layer 95 Stream class about 40 get method 40 tips and tricks 55 Stream get method 40 Stream length ...

Page 113: ... Dreamweaver MX 93 V var using for local variables 104 vhost xml file 58 video broadcasting 57 codecs 58 delivery 58 live broadcast 57 On V6 codec 58 See also Video class Sorenson H263 codec 58 streaming 58 Video class about 38 56 and Camera get method 38 and NetStream play method 38 attachVideo method 38 tips and tricks 56 video codecs about 58 On2 V6 58 Sorenson H263 58 Video objects creating dy...

Page 114: ...114 ...

Reviews: