Flash/flex Study Notes (10): Hello world of the FMS 3.5!

Source: Internet
Author: User

Adobe's FMS is really a cool technology! (At least Silverlight does not show any signs that it can surpass the FMS in "real-time broadcast)

Almost all of Tudou, ku6, first video... and many other video sharing websites used Adobe's FMS technology.

Today, let's make a simple hello World (the example is from the official documentation of FMS)

1. Create an FMS application helloworld first

Go to the default installation directory of FMS: C: \ Program Files \ Adobe \ Flash Media Server 3.5 \ applications

Create a helloworld directory.

2. Open flash cs4, create a flash file (actionscript3.0), and save it as "helloworld. fla"

Drag the two buttons to the stage and name them btnconn and btndisconn. The label text is: "connect to FMS", "disconnect from FMS"

Drag a label to the stage and name it lblresult to display the operation result.

Write the following on the first frame:Code:

Import flash.net. netconnection; import flash. events. mouseevent; import flash. events. netstatusevent; var NC: netconnection; // register the event btnconn. addeventlistener (mouseevent. click, btnconnclick); btndisconn. addeventlistener (mouseevent. click, btndisconnclick); function btnconnclick (E: mouseevent) {If (NC = NULL) {NC = new netconnection (); NC. addeventlistener (netstatusevent. net_status, connhandler); // the Conn is automatically called whenever the connection status changes. Handlernc. connect ("rtmp: // localhost/helloworld"); lblresult. TEXT = "connecting to FMS... ";}} function btndisconnclick (E: mouseevent) {If (NC! = NULL) {NC. close (); NC = NULL ;}} function connhandler (E: netstatusevent) {trace (e.info. code); Switch (e.info. code) {Case "netconnection. connect. closed ": lblresult. TEXT = "Disconnect successfully"; break; Case "netconnection. connect. failed ": lblresult. TEXT = "connection attempt failed"; break; Case "netconnection. connect. success ": lblresult. TEXT = "connection successful"; var resp: responder = new Responder (onreply); NC. call ("serverhellomsg", resp, "Hi FMS! "); // Call the serverhellomsg method break of the server; Case" netconnection. Connect. Rejected ": lblresult. Text =" the connection attempt did not access the application.Program "; Break; default: lblresult. TEXT = e.info. code; break ;}} function onreply (E: Object) {trace ("server returned content:" + E); lblresult. TEXT = E. tostring ();}

The above demonstrates how to "connect to the server", "Disconnect", and "Call the server method". Do not rush to run it because the serverhellomsg method on the server has not been written yet.

3. Create an SSP server code

Go to c: \ Program Files \ Adobe \ Flash Media Server 3.5 \ applications \ helloworld to create a text file main. ASC and write the following code

 
Application. onconnect = function (client) {client. serverhellomsg = function (hellostr) {trace (hellostr); Return "hello," + hellostr + "! ";}Application. acceptconnection (client );}

The server has two special objects: Application and client. They are used to generate "application instance" and "reference to the client". Note the trace (hellostr) of the server ), we know that the trace information in Flash cs4 will be displayed in the Flash output window, but the server does not have an output window, and the output information will be automatically saved

C: \ Program Files \ Adobe \ Flash Media Server 3.5 \ logs \ _ defaultvhost _ \ helloworld \ _ definst _ \ application. XX. Log

The saved content is similar to the following:
# Version: 1.0

# Start-Date: 2010-03-14 13:38:08

# Software: Adobe Flash Media Server 3.5.1 r516

# Date: 2010-03-14

# Fields: Date Time X-pid X-status X-ctx x-Comment

2010-03-14 13:38:05 8152 (s) 2641173Hi FMS! -

 

Okay, go back to flash cs4 and press Ctrl + enter to run it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.