Performance of Flash 10.1 LocalConnection

Source: Internet
Author: User

Flash uses LocalConnection to process communication between two Flash files. For a simple example, refer to: Use LocalConnction to communicate with SWF.

After the Flash plug-in is upgraded to 10.1, it is found that the application is slow. The final reason is that the name starts, "_" is exactly the marker of unpredictable communication between different domains in LocalConnection.

LocalConnection is used differently in different domain environments (in the same domain, in different domains with predictable domain names, and in different regions with unpredictable domain names:

1. The same domain. This is the simplest case for LocalConnector objects. Only LocalConnection objects in the same domain can communicate with each other. special security measures are not required, you only need to communicate according to the same value of the connecionName parameter:

Receiver.swf:

            public function Init():void{
                var conn:LocalConnection=new LocalConnection();
                conn.client=this;
                try{
                    conn.connect("connectionName");
                }
                catch(error:ArgumentError){
                    trace("connectionName exists");
                }
            }
 
            public function testHandler(msg:String):void{
 
            }

Sender.swf:

var conn:LocalConnection;
conn=new LocalConnection();
conn.send("connectionName", "testHandler", "Hello World!");

 

2. different domains of predictable domain names. When two Flash files in different domains communicate with each other, you need to call the allowDomain () method to run the two Flash files to communicate within these two domains. In the send () method of the sender Flash, use the Domain Name of the LocalConnection object of the receiver to limit the connection name:

Receiver.swf (in the.com domain ):

public function Init():void{
    var conn:LocalConnection=new LocalConnection();
    conn.allowDomain("www.b.com");
    conn.client=this;
    try{
        conn.connect("connectionName");
    }
    catch(error:ArgumentError){
        trace("connectionName exists");
    }
}
 
public function testHandler(msg:String):void{}

Sender.swf (in the www. B .com domain ):

var conn:LocalConnection;
conn=new LocalConnection();
conn.send("a.com:connectionName", "testHandler", "Hello World!");

 

3. different domains of unpredictable domain names. LocalConnection uses allowDomain (*) to allow calls from all domains. You can also call the allowDomain () method multiple times to add allowed domains. in different unpredictable domains, you must add an underscore ("_") before the name of connectName.

Receive.swf:

public function Init():void{
    var conn:LocalConnection=new LocalConnection();
    conn.allowDomain("*");
    conn.client=this;
    try{
        conn.connect("_connectionName");
    }
    catch(error:ArgumentError){
        trace("connectionName exists");
    }
}
 
public function testHandler(msg:String):void{}

Sender.swf:

var conn:LocalConnection;
conn=new LocalConnection();
conn.send("_connectionName", "testHandler", "Hello World!");

 

Again, do not start with "_" for LocalConection communication in the same domain as "connectName.

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.