Flex improvement --- detailed explanation of jsonobject objects

Source: Internet
Author: User
Tags sendmsg

Jsonobject, as its name implies, shares objects. In general sense, sharing is nothing more than client (browser) Sharing and server sharing in B/S structure, jsonobject just plays these two roles. In addition, jsonobject is classified according to the following two types: LSO -- local Share Object (local shared object) is similar to cookie, another RSO-remote Share Object (Remote shared object) is similar to the Application Object in JSP, But it seems more powerful than the application.

 

The usage and usage of the two are described in the following example code:

 

I. LSO (local shared object)

The usage of LSO is relatively simple, which is similar to that of cookies:

1. Get a shared object:

VaR so: Export dobject = export dobject. getlocal ("mydata ","/");

2. Save the value to the shared object:

VaR User: Object = new object ();

User. Username = username. text;

User. Password = password. text;

User. issavelogin = (remember. Selected = true? 1-0 );

So. Data. User = user;

3. Clear the values in the shared object:

VaR so: Export dobject = export dobject. getlocal ("mydata ","/");

If (so. Data. User! = NULL ){

So. Data. User = NULL;

}

4. Read the value of the shared object:

VaR so: Export dobject = export dobject. getlocal ("mydata ","/");

If (so. Data. User! = NULL ){

Username. Text = So. Data. User. Username;

Password. Text = So. Data. User. Password;

If (so. Data. User. issavelogin. tostring () = "1 "){

Remember. Selected = true;

}

 

Ii. RSO (Remote shared object ):

RSO is a shared object on the server. Data Sharing on the server can be used to share data between multiple clients. Here, I use Flash Media server3 on the server, which is very easy to use, you only need to find the applications directory under the installation directory and create a new sub-directory under it to become your project or project. You can refer to the relevant articles for the use of FMS. This article will not introduce you: Using FMS and RSO, we can implement many functions, such as chatting rooms, online games, video conferences, online Video Recording and video chat ......

Here I will use a simple chat room instance as an example to explain:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" creationcomplete = "textso ();"> <br/> <mx: SCRIPT> <br/> <! -- [CDATA [<br/> Import flash. events. syncevent; <br/> Import flash. events. netstatusevent; <br/> Import flash. events. mouseevent; <br/> Import flash.net. export dobject; <br/> Import flash.net. netconnection; </P> <p> private var text_so: Empty dobject; <br/> private var NC: netconnection; <br/> private var rtmpgo: string; <br/> private var good: Boolean; </P> <p> Public Function textso (): void <br/>{< br/> button. label = "send"; <br/> button. addeventlistener (mouseevent. click, sendmsg); // Add a send event for the send button <br/> rtmpgo = "rtmp: // localhost/basicso"; // set the connection address of the FMS server, basicso is, <br/> // The name of a folder manually created under applications in the installation directory of the Microsoft operating system. It is also the project name of the Microsoft operating system, which is so concise, not negotiable <br/> NC = new netconnection (); // generate a connection object <br/> NC. connect (rtmpgo); // connect to the above address <br/> NC. addeventlistener (netstatusevent. net_status, Doso); // adds a connection listening event to facilitate corresponding processing based on the Status returned by the connection <br/>}</P> <p> private function Doso (E: netstatusevent): void <br/>{< br/> good = e.info. code = "netconnection. connect. success "; // determine whether the connection is successful <br/> // There are several statuses returned by the connection. For details, refer to the documentation of the FMS, very detailed <br/> If (good) // If connected to Shi, perform the following operations <br/>{< br/> text_so = export dobject. getremote ("test", NC. uri, false); // obtain the remote shared object. The false attribute sets the shared data to be non-persistent. <br/> // After the server is restarted, the previous data is not saved <br/> text_so.connect (NC); <br/> text_so.addeventlistener (syncevent. sync, checkso); <br/> // Add an asynchronous event to the shared object, which is also the most critical part for the server to process multiple clients synchronously, <br/> // What operations a client performs, and other clients also change accordingly, <br/>}</P> <p> private function checkso (E: syncevent ): void <br/> {<br/> for (VAR Chng: uint; Chng <E. changelist. length; Chng ++) <br/>{< br/> switch (E. changelist [Chng]. code) <br/>{< br/> case "clear": <br/> break; </P> <p> case "success ": <br/> trace (text_so.data.msg); <br/> break; </P> <p> case "change ": // when a client changes data, all clients are updated. <br/> textarea.html text + = text_so.data.msg + "/N"; <br/> break; <br/>}</P> <p> private function sendmsg (E: mouseevent ): void <br/>{< br/> text_so.setproperty ("MSG", textinput. text); // Save the new information to the shared object <br/> textarea.html text + = text_so.data.msg + "/N "; // update the client information list <br/>}</P> <p>] --> <br/> </MX: SCRIPT> <br/> <mx: vbox> <br/> <mx: textarea id = "textarea" width = "200" Height = "200"/> // information list box <br/> <mx: textinput id = "textinput"/> // message input box <br/> <mx: button id = "button"/> // send button <br/> </MX: vbox> <br/> </MX: Application>

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.