views:

59

answers:

2

Hiya. I'm trying to communicate between a flex 4.1 application to a flash action script 2 application using LocalConnection.

flash application

contains a button called btn01 and the following code:

var a:LocalConnection = new LocalConnection();

btn01.onPress = function() {
 trace("button clicked");
 a.send("abcde","test");
}

you can see here that it sends a test command to the connection named 'abcde'.

flex application

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"     minHeight="600" initialize="init()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import mx.controls.Alert;

        private function init():void {
            var a:LocalConnection = new LocalConnection();
            a.client=this;
            a.connect("abcde");
        }

        public function test():void {
            Alert.show("test");
        }
]]>
</fx:Script>
<mx:SWFLoader source="/location/as2-flash-file.swf" />

as you can see, in the flex application i connect to LocalConnection named 'abcde' and i set the client to 'this' which means that all the public functions can be executed from the LocalConnection.

the SWFLoader element loads the as2 flash file.

whenever i click the button i do see the trace message but the function test does not get executed on the flex application. any ideas?

update

both applications sit on the same domain, on the localhost actually so no need for allowDomain usage and both applications are web based.

+1  A: 

Documentation says AS2 and AS3 LocalConnections should communicate no problems.

Do you need to look into the allowDomain method? Do you need to put a crossdomain.xml file in place? If you do have swfs on two different domains, pay special attention to the send method documentation, because you you have to add additional info to the send method's connection name.

Are they both browser based applications? I not, look into AIR

www.Flextras.com
thanks for info, i updated main post with more details. i did not find a solution yet.
ufk
+1  A: 

I created the LocalConnection variable within the init() scope, so when the function ended the localconnection was destroyed. the solution is just to declare the variable outside of the init function.

public var a:LocalConnection;

private function init():void {
        a = new LocalConnection();
        a.client=this;
        a.connect("abcde");
    }
ufk
I can't believe I didn't catch that. Good job!
www.Flextras.com