
119
FLASH
MEDIA
SERVER
4.5
CONFIGURATION
AND
ADMINISTRATION
Using the Administration API
Last updated 11/28/2012
Note:
You can call Administration APIs from applications written in ActionScript 1.0, ActionScript 2.0, or ActionScript 3.0.
1
In Flash, create an application with the following elements:
•
An input text field named
appName
•
A button called
button_btn
•
A multiline, dynamic text field called
outputBox
•
A scroll component attached to the
outputBox
text field
Note:
Because this is a Flash Media Server application, you must create an application directory with the application
name in the RootInstall\applications directory.
2
Enter the following code on frame 1 of a Flash file:
/** Establishes the connection to Flash Media Server **/
ncAdmin = new NetConnection();
// Replace admin_name and admin_pass with your
// administrator name and password.
ncAdmin.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);
}
};
}
// Calls the getAppStats() API on the name of application
// in the input text field
// places the response in the onGetAppStats funtion
ncAdmin.call("getAppStats", new onGetAppStats(), appName.text);
}
function printObj(obj, destination){
for (var prop in obj) {
destination.text += "\t";
destination.text += prop + " = " + obj[prop] + newline;
if (typeof (obj[prop]) == "object") { // recursively call printObj
printObj(obj[prop], destination);
}
}
}
button_btn.onRelease = function(){
doGetAppStats();
}
3
Before running this sample application, start another Flash Media Server application.
4
Open the Administration Console to verify that the application you started in step 3 is running.
5
Run the sample Flash application and enter the name of the application you started in step 3 in the input text field.