Communicate Flash Movie using LocalConnection Class
Macromedia Flash has a special class called LocalConnection that allows you to communicate between swf that resides on the same client machine and on the same domain but are performing different operation. This is useful in a scenario where you want to pass data from one swf to another without using JavaScript.
Methods used in LocalConnection Class:
- send(Local Connection Name,Method Name)
This method will send the data between the swf. The Local Connection Name refers to the name of the localconnecion Object. The method name refers to the function that will be called after successful sending the data.
- connect(Local Connection Name)
This method will try to connect to the swf having the Local Connection Name specified in the argument.
- close()
This method closes/destroys the localconnection object.
Typical Example:
Suppose i have two Flash Movie Movie1 and Movie2 and you want to send data from Movie1 to Movie2
Action Script Code for Move1 on the first frame:
sender = new LocalConnection();
sender.send(”connection1″, “connection_method”,data);
- Here we have create a instance of Local Connection class by name “sender“
- “connection1” refers to the movie1 localconnection name
- “connection_method” is the function name to be called after sending data
- “data” will be the information that needs to be passed. The data can a string or numbers
Action Script Code for Move2 on the first frame:
reciever = new LocalConnection();
reciever.connection_method = function(x)
{
trace(x);
};
reciever.connect(”connection1″);
- Here we create a new LocalConnection instance.
- Also we define the connection_method for the reciever object.
- Finally the localconnection object connects to the connection send by Movie1.
Related Post
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.












































Comments
No comments yet.
Leave a comment