首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

LocalConnection 同一域中两个swf通讯失败解决思路

2012-05-05 
LocalConnection 同一域中两个swf通讯失败很简单的一个例子,不知道为什么总是通讯失败。两个文件send.mxml

LocalConnection 同一域中两个swf通讯失败
很简单的一个例子,不知道为什么总是通讯失败。
两个文件send.mxml和receive.mxml,代码分别如下:
receive.mxml:

Java code
<?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" creationComplete="send_creationCompleteHandler(event)">        <fx:Script>        <![CDATA[            import mx.events.FlexEvent;                        private var conn:LocalConnection=new LocalConnection();            protected function send_creationCompleteHandler(event:FlexEvent):void            {                // TODO Auto-generated method stub                conn.addEventListener(StatusEvent.STATUS,onStatus);            }                        protected function btn_send_clickHandler(event:MouseEvent):void            {                // TODO Auto-generated method stub                conn.send("conn","sMethod");            }                        protected function onStatus(e:StatusEvent):void            {                trace(e.level);            }        ]]>    </fx:Script>        <fx:Declarations>        <!-- 将非可视元素(例如服务、值对象)放在此处 -->    </fx:Declarations>    <s:Button x="240" y="186" label="发送消息" click="btn_send_clickHandler(event)"/></s:Application>


receive.mxml:
Java code
<?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" creationComplete="receive_creationCompleteHandler(event)">    <fx:Script>        <![CDATA[            import flash.net.LocalConnection;            import mx.events.FlexEvent;            public function sMethod():void            {                textA.appendText("just a test!");            }                        protected function receive_creationCompleteHandler(event:FlexEvent):void            {                // TODO Auto-generated method stub                var conn:LocalConnection=new LocalConnection();                conn.client=this;                try                {                    //conn.allowDomain('*');                    conn.connect("conn");                }                catch(er:ArgumentError)                {                    trace(er.toString());                }            }                    ]]>    </fx:Script>    <fx:Declarations>        <!-- 将非可视元素(例如服务、值对象)放在此处 -->    </fx:Declarations>    <s:TextArea x="203" y="103" width="328" height="196" id="textA"/></s:Application>


点击receive.mxml中的"发送消息"按钮,StatusEvent.level总为"error",求教。。。

[解决办法]
到底哪个是 send 哪个是 receive ?

呵呵,你好像把文件名搞错了。第一个是 send 吧?

热点排行