Macromedia flash media server 2-server-side actionscript language reference Benutzerhandbuch

Seite von 74
A simple application example
7
A simple application example
This section contains the code for a simple Flash application that calls the 
getAppStats
 
method. You can copy and paste this code into Flash to see how a simple call works.
In Flash, create an application with the following elements: 
An input field named Application Name with a border
A button that calls the 
doGetAppStats()
 method (shown in the code sample that 
follows)
A multiline, dynamic text field called outputBox that has a border
A scroll component next to the text field
This simple interface lets you test the Server Management ActionScript API.
Next, in the Actions panel, enter the sample ActionScript code that follows. Be sure to replace 
admin_name
 and 
admin_pass
 with your valid administrator name and password.
/** Establishes the connection to Flash Media Server **/
nc = new NetConnection();
nc.connect("rtmp://localhost:1111/admin","admin_name","admin_pass");
/** Makes the API call, for example, "GetAppStats" **/
function doGetAppStats() {
function onGetAppStats()
{
this.onResult = function(info)
{
if (info.code != "NetConnection.Call.Success")
outputBox.text = "Call failed: " + info.description;
else {
outputBox.text = "Info for "+appName.text+ " returned:" + ¬ 
newline;
printObj(info, outputBox);
}
}
}
nc.call("getAppStats", new onGetAppStats(), appName.text);
}
// This function proceeds through an object, printing all values to the
// destination, including recursively printing objects within objects.
// The tabLevel parameter is used for cosmetic purposes.
function printObj(obj, destination, tabLevel)
NO
TE
The continuation character (
¬
) indicates that the code continues to the next line; this 
character should not appear in code.