答案 0 :(得分:0)
您需要写入同一个SharedObject的所有内容都是为两者指定相同的mySO = SharedObject.getLocal("myObjectFile","/");
import flash.net.SharedObject;
var iterations:int = 100
function witeToSo()
{
var mySO:SharedObject = SharedObject.getLocal("myObjectFile", "/");
if (iterations > 0)
{
if (!mySO.data.str) mySO.data.str = ""
mySO.data.str += int(Math.random() * 10);
iterations--;
}
txt.text = "str: " + mySO.data.str + " symbolsTotal:" + (mySO.data.str.length) + "\n";
setTimeout(witeToSo, Math.random()*100);
}
setTimeout(witeToSo, 2000);
此处有更多信息http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d80.html
这是一个简短的代码,可以确保数据不会丢失,工作人员实际上正在执行与多个闪存播放器同时运行相同的内容。只需运行2个或更多swf并查看结果:
CREATE TABLE t
(
id varchar(10), /* possibly a PRIMARY KEY, but not sure */
tnstime timestamp,
/* Don't use a varchar if the list of status is predefined and fixed */
status ENUM ('completed', 'submited', 'failed'),
/* This should be unique in any case, so, let's make it the PK */
PRIMARY KEY (id, tnstime)
) ;
另外,您需要考虑如何在需要按特定顺序写入数据的情况下同步线程