【发布时间】:2012-04-02 18:33:02
【问题描述】:
我目前在 playbook 上有一个具有以下类的移动应用程序:
[Bindable]
public class Foo
{
public var myString:String;
public var myList:ArrayCollection;
public function Foo() {}
}
我的ViewNavigatorApplication 中也有persistNavigatorState="true"。
假设在我的第一个视图中,我的creationComplete="init()" 呼叫中有以下内容:
private function init():void {
var s:String = "test_string";
var a:ArrayCollection = new ArrayCollection();
a.addItem("test1");
a.addItem("test2");
a.addItem("test3");
data.foo = new Foo();
data.foo.myString = s;
data.foo.myList = a;
trace(data.foo.myString);
trace(data.foo.myList[0]);
trace(data.foo.myList[1]);
trace(data.foo.myList[2]);
}
执行后,我的应用程序一切正常。但是,由于我希望会话持续存在,以防用户意外关闭应用程序,因此当他重新打开应用程序时,数据应该仍然存在。
相反,当我关闭并重新打开我的应用程序时,只有 myString 属性仍然存在(即跟踪“test_string”,如预期的那样),但不会复制 ArrayCollection。
我用ObjectUtil.clone() 和ObjectUtil.copy() 尝试了以下操作:
data.foo.myString = ObjectUtil.copy(s) as String;
data.foo.myList = ObjectUtil.copy(a) as ArrayCollection;
我也试过了:
var f:Foo = new Foo();
f.myString = s;
f.myList = a;
data.foo = ObjectUtil.copy(f) as Foo;
trace(data.foo.myString);
trace(data.foo.myList[0]);
但这只会给我一个
TypeError:错误 #1009:无法访问空对象引用的属性或方法。
关于如何在移动应用程序中持久化 ArrayCollections 和 Foo 类有什么想法吗?
【问题讨论】:
标签: actionscript-3 apache-flex blackberry-playbook