LocalConnection In AS3

4.4k views Asked by At

I'm trying to use LocalConnection in AS3 between two AS3 movies (made in CS5) but it doesn't seem to be working, here is the current code (each in frame1 (the only frame) of each movie on layer 1 (the only layer))

Sender:

import flash.external.ExternalInterface;
import flash.net.LocalConnection;

function sendtoview(con,val):String {
//create local connection for sending text
var sending_lc:LocalConnection = new LocalConnection();
//put text from input into a var
sending_lc.addEventListener(StatusEvent.STATUS, err);
//send through specified connection, call specified method, send specified parameter
ExternalInterface.call("alert('Sending...')");
sending_lc.send("xivioview", "recieveText", val);
return "kk"
}

function err(msg) {
    ExternalInterface.call("alert('" + msg + "')");
}

ExternalInterface.addCallback("sendtoview", sendtoview);
ExternalInterface.call("alert('Loaded')");

Note that I know the JavaScript connection to the ExternalInterface does work, I've tested it.

Receiver:

import flash.external.ExternalInterface;
import flash.net.LocalConnection;

var mLocalConnection:LocalConnection = new LocalConnection();
mLocalConnection.connect("xivioview");
mLocalConnection.client=this;

function recieveText(textRecieved:String) {
ExternalInterface.call("alert('Received!')");
ExternalInterface.call(textRecieved);
};



ExternalInterface.call("alert('Loaded')");

If you don't want to fix my code I'd still be happy with a working simple example (i've searched google for hours, none seem to be easy or simple.).

1

There are 1 answers

0
Ribs On BEST ANSWER

You might be better off checking out Grant Skinner's SwfBridge class. Makes LC's very easy to do.

http://gskinner.com/blog/archives/2007/07/swfbridge_easie.html