views:

273

answers:

1

I have a Flash CS4 AS3 swf (host) that loads a Flash 8 AS2 swf (client) using gSkinner's swfBridge.

This works great and the Host can call functions in the client no problem. However I want to be able to call a function in the client and have that function return an array to the host.

This is the code I thought would work -

Host (AS3) code -

var hostArray:Array = new Array();
hostArray = mySwfBridge.send("getArray");

Client (AS2) code

var theArray = new Array("item1, item2, item3);
function getArray() :Array {
    return theArray;
}

any ideas?

+1  A: 

The problem your exposed towards is that the LocalConnection (used by SwfBridge) does it calls asynchronously. In other words, the execution of the caller script won't halt its execution to await a result back from the invoked function.

If you need to retrieve a value from the other side of the LocalConnection you need to set it up to work bidirectionally. i.e. your client script must send its result back to a callback method on the host object via LocalConnection (SwfBridge in this case) instead of doing this via return.

Theo.T
Thanks Theo, by a callback method, do you mean that when the called function has completed I simply call a function in the original caller to handle what would have been sent by the return statement. I had thought of this but thought it was a bit untidy... if thats the only way though... many thanks :)
undefined