PDA

View Full Version : swf communication


J_Buda
02-14-2008, 11:12 AM
is it possible to have 2 swfs, that are not in a browser window.... communicate with each other?

If not, how would this be possible?

panel
02-14-2008, 12:09 PM
LocalConnection class

Send

import flash.net.LocalConnection;

private var _localConnection:LocalConnection;

_localConnection = new LocalConnection();

_localConnection.send("ConnectionName" , "someFunction", Paramateres.partId);



Recieve

import flash.net.LocalConnection;

private var _localConnection:LocalConnection;

_localConnection = new LocalConnection();
_localConnection.connect("ConnectionName");
_localConnection.client = this;
_localConnection.addEventListener(StatusEvent.STAT US, onStatus);

private function onStatus(event:StatusEvent):void
{
switch (event.level) {
case "status":
// trace("LocalConnection.send() succeeded");
break;
case "error":
//trace("LocalConnection.send() failed");
break;
}
}

public function someFunction(partId:Number):void
{
trace("someFunction")
}

J_Buda
02-14-2008, 12:21 PM
thanks for the reply...

Do the swfs need to be embedded within a html document? or can they just be 2 swfs sitting on the desktop?

panel
02-14-2008, 01:42 PM
LocalConnection objects can communicate only among SWF files that are running on the same client computer, but they can be running in different applications — for example, a SWF file running in a browser and a SWF file running in a projector. (A projector is a SWF file saved in a format that can run as a stand-alone application — that is, without Flash Player.)

J_Buda
02-14-2008, 03:46 PM
Hi

have implemend this into 2 separate swf.

And im getting this errror...

Error #2044: Unhandled StatusEvent:. level=error, code=

I have the send function in one document class, and i have crated another document class the other swf with the receiving code that you posted.

Both the swf files are in the same directory too

panel
02-14-2008, 03:52 PM
Ah I did it with many instance of the same swf so it worked for me but I am guessing that you have to also add StatusEvent listener in 'Send swf' (the same way as in Recive)

J_Buda
02-14-2008, 03:55 PM
i have just added an error hanlder for the sender, as it seems to fail just sending it. I put a trce for the event, and its just display this...

[StatusEvent type="status" bubbles=false cancelable=false eventPhase=2 code=null level="error"]

Not sure what the problem seems to be.

Could you help me?

Jusr read your last post, not sure i know what you mean with regards to the same swf but many instances?

J_Buda
02-14-2008, 04:00 PM
Ignore my last posts....

Just realised that the receiving swf was not playing at the time.

Your code worked fine, thanks!