Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

localconnection

Status
Not open for further replies.

0gani

Technical User
Oct 9, 2006
14
SK
What's wrong with this code?

AS3
Code:
import flash.external.ExternalInterface;
import flash.net.*;
var AVM_lc:LocalConnection = new LocalConnection();
AVM_lc.connect("thisconnection");

AVM_lc.showalert= function()
{
ExternalInterface.call("alert", "hey it worked");
}


AS2
Code:
var AVM_lc:LocalConnection = new LocalConnection();
AVM_lc.send("thisconnection", "showalert");

 
Sender - AS3
Code:
import flash.net.LocalConnection;
var AVM_lc:LocalConnection = new LocalConnection();
function sendMessage(event:MouseEvent):void{
	AVM_lc.send("thisconnection", "showalert");
}
sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);

Receiver - AS3
Code:
import flash.external.ExternalInterface;
import flash.net.LocalConnection;
var AVM_lc:LocalConnection = new LocalConnection();
AVM_lc.client = this;
AVM_lc.connect("thisconnection");
function showalert():*{
	ExternalInterface.call("alert", "hey it worked");
}

Kenneth Kawamoto
 
Thanks

how would this work if i wanted two-way communication?
 
anyone have any idea how to do this for two-way communication?
 
LocalConnection offers one way communication per connection and I don't think that has changed in AS3.

The following AS3 example will send messages to both directions between two SWFs (using two connections); may be this is close to what you have in mind.

SWF A
Code:
import flash.net.LocalConnection;
var AVM_lc:LocalConnection = new LocalConnection();
AVM_lc.client = this;
AVM_lc.connect("connectionB-A");
function sendMessage(event:MouseEvent):void{
	AVM_lc.send("connectionA-B", "showalert", "From A to B");
}
sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);
function showalert(str:String):void{
	tf.text = str;
}

SWF B
Code:
import flash.net.LocalConnection;
var AVM_lc:LocalConnection = new LocalConnection();
AVM_lc.client = this;
AVM_lc.connect("connectionA-B");
function sendMessage(event:MouseEvent):void{
	AVM_lc.send("connectionB-A", "showalert", "From B to A");
}
sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);
function showalert(str:String):void{
	tf.text = str;
}

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top