我正在使用本地共享对象作为在两个同时运行的swf之间传输数据的方法。
so = getLocal("mySO");
// set the value from a user input, and set it to 'connected'
so.setProperty(txtName.text, "connected")
// every few seconds check if the other SWF started and modified value
onTimer
{
var data:Object = so.data
// breakpoint and inspect the data with debugger
}
最后一个注释行是问题所在。在调试器中,没有检测到数据更改,但在使用.minerva检查.sol文件时,我看到了两个SWF的更改。因此,尽管SWF 2修改了共享对象,但SWF 1没有看到这些更改。这是怎么回事?
ps:我知道我可以使用LocalConnection在两个正在运行的SWF之间进行通信,但是如果存在某种限制,仍然想知道SO。
更新:
从磁盘运行已编译的Flex应用程序两次,将“swf2”放入第二个文本字段中。按两下开始。启动的第一个从未检测到第二个连接。
<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="application1_creationCompleteHandler(event)"
>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var timer:Timer;
private var so:SharedObject;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
so = SharedObject.getLocal("mySO");
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, onTimer);
}
protected function button1_clickHandler(event:MouseEvent):void
{
so.setProperty(txtSwf.text, 'connected');
so.flush();
timer.start();
}
protected function onTimer(event:TimerEvent):void
{
so = SharedObject.getLocal("mySO");
txtLog.text += so.data["swf1"] + "\n";
txtLog.text += so.data["swf2"] + "\n";
txtLog.text += "------------ \n";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextInput id="txtSwf" x="10" y="50" text="swf1"/>
<s:Button x="170" y="50" label="Start" click="button1_clickHandler(event)"/>
<s:TextArea id="txtLog" x="10" y="154" width="279" height="112" />
</s:Application>
答案 0 :(得分:0)
您需要强制读取文件,而不是客户端已有的数据:/
so = getLocal("mySO");
// set the value from a user input, and set it to 'connected'
so.setProperty(txtName.text, "connected")
// every few seconds check if the other SWF started and modified value
onTimer
{
so = getLocal("mySO"); // read the so file.
var data:Object = so.data
}
答案 1 :(得分:0)
so = getLocal("mySO");
// set the value from a user input, and set it to 'connected'
so.setProperty(txtName.text, "connected")
// every few seconds check if the other SWF started and modified value
onTimer
{
so = getLocal("mySO"); // read the so file.
var data:Object = so.data;
so = null // MAKE IT NULL AND HOPE IT'S GC'D BEFORE NEXT TIMER
}
技巧是在使用后将其设置为null,然后强行重新读取并从其他SWF实例写入的值被拾取。