Flash/flex Study Notes (15): Remote shared object (Remote shared object) in the FMS 3.5)

Source: Internet
Author: User

The "remote shared object" in the FMS allows flash applications on multiple clients to share the same global object. When any of the clients changes this object, the system automatically sends the object back to the FMS server, and the FMS server broadcasts the object to all clients.

 

More broadly speaking: If the FLASH application is browsed on two machines, the operations performed on one machine will be reflected in the synchronization of the other machine.

 

What can this do? Electronic classrooms (for example, teachers can demonstrate teaching on one machine, and all other machines can be refreshed simultaneously), interactive games (for example, couples in the game can decorate their houses in different places ), the chat room application that needs to save records on the server (treat the chat room record as a shared object )...

 

The followingCodeThe official example of the source of the FMS is to drag the position of the ball on one machine, and the ball on the other machine will also move synchronously.

VaR NC: netconnection = new netconnection (); var so: Export dobject; NC. addeventlistener (netstatusevent. net_status, netstatushandler); // sharedball is a small ball instance on the stage. addeventlistener (mouseevent. mouse_down, pickup); sharedball. addeventlistener (mouseevent. mouse_up, place); sharedball. addeventlistener (mouseevent. mouse_move, moveit); sharedball. addeventlistener (mouseevent. mouse_over, mouseoverhandler); sharedb All. addeventlistener (mouseevent. mouse_out, mouseouthandler); function mouseoverhandler (E: mouseevent) {mouse. cursor = mousecursor. hand;} function mouseouthandler (E: mouseevent) {mouse. cursor = mousecursor. arrow;} NC. connect ("rtmp: // localhost/sharedball"); // connect to fmsfunction netstatushandler (E: netstatusevent) {Switch (e.info. code) {Case "netconnection. connect. success ": trace (" Congratulations! You're connected "); so = export dobject. getremote ("ballposition", NC. uri, false); so. connect (NC); so. addeventlistener (syncevent. sync, synchandler); break; default: break;} function pickup (E: mouseevent): void paie.tar get. startdrag ();} function place (E: mouseevent): void paie.tar get. stopdrag ();} function moveit (E: mouseevent): void {If (so! = NULL) {// when moving, modify the so attribute value of the shared object. setproperty ("X", sharedball. x); so. setproperty ("Y", sharedball. y) ;}} function synchandler (E: syncevent): void {// so has an object data to save the trace (SO. data. x); trace (SO. data. Y );//Program When you enter the shared object for the first time, the shared object has no value. Therefore, you need to determine the initial value if (SO. data. X = undefined | so. data. y = undefined) {sharedball. X = 50; sharedball. y = 50;} else {sharedball. X = so. data. x; sharedball. y = so. data. Y ;}}

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.