Implementation of chatting in the MS tutorial

Source: Internet
Author: User

There are many ways to implement chat in the MS, mainly using mongodobject. Today, let's talk about how mongodobject implements chat:
The most amazing thing about mongodobject is that as long as it changes, all clients connected to it will receive messages and respond. This action must be completed in onsync of the client.

Method 1: assign a value to dobject:

Create a folder named chat in the applications directory and do not need to write main. ASC.

Two text boxes are placed on the scene. One is the input text, the dynamic text, and the other is a button.

The names are: input_txt output_txt chat_btn.

// Code begin

// Code begin
VaR NC: netconnection = new netconnection ()
NC. onstatus = function (Info ){
Trace (info. Code)
}
NC. Connect ("rtmp:/chat", "Lulu ");

VaR chat_so: Export dobject = export dobject. getremote ("chat", NC. Uri, false );
// Monitoring function
Chat_so.onsync = function (){
// Read the data as long as the change occurs and make it realistic in output_txt
If (this. Data. Text = undefined ){
This. Data. Text = "";
} Else {
_ Root. output_txt.text = This. Data. text;
}
}
Chat_so.connect (NC)
Chat_btn.onrelease = function (){
_ Root. chat_so.data.text + = _ root. input_txt.text + "/N ";
_ Root. input_txt.text = "";
}
// Code end

CTRL + enter ..

If you change the value of red false to true, you can view the previous chat record next time you connect to the server ..
PS: if the client wants to write attributes in so, it must be in chat_so.data mode to assign values to it. Data here is equivalent to chat_so on the server.
The example is to save the chat record by writing the attribute text to it.

Sleepy, the next method will be written tomorrow night... Play football first .. Not a game.

200706042222540824. rar

 

The method used in tutorial 4 is to write the attribute in mongodobject. After the attribute is changed, all clients are synchronized to implement text chat.
In this case, I will describe a simpler implementation method: using export dobject. Send.

Similarly, create a folder chat in the applications directory without writing to create main. ASC.

Two text boxes are placed on the scene. One is the input text, the dynamic text, and the other is a button.

The names are: input_txt output_txt chat_btn.

// Code begin
VaR NC: netconnection = new netconnection ()
NC. onstatus = function (Info ){
Trace (info. Code)
}
NC. Connect ("rtmp:/chat", "Lulu ");
VaR chat_so: Export dobject = export dobject. getremote ("chat", NC. Uri, false );
// The onsync function is not required, because the data of chat_so will not change.
Chat_so.connect (NC)
Chat_so.showchat = function (txt: string ){
_ Root. output_txt.text + = TXT + "/N ";
}
Chat_btn.onrelease = function (){
// The send method is used here. Note that showchat is the showchat function defined above, followed by the passed parameters, and multiple parameters can be passed.
_ Root. chat_so.send ("showchat", _ root. input_txt.text );
_ Root. input_txt.text = "";
}
// Code end

CTRL + enter .....
What is the main difference between this method and the first method?
1. The first method can record chat information, and the second method cannot.
2. The communication volume of the first method is relatively large. Each time, all the information must be read locally, and the second method is very small.
3. The second method is more flexible. Users can delete the records of their chat areas. If the first method is used, so can only be deleted by persons with management permissions. data, so. data. TEXT = "";

Playing football ..
Let's talk about the main usage of netstream tomorrow and the popular on-demand and live video streaming.

Attach source file

200706052111551816. fla

 

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.