17.2.写入数据到共享对象上

问题
我想添加数据到LSO上.
解决办法
给共享对象的data对象添加属性值
讨论
共享对象(Shared objects)有个内建的属性data,data属性类型为object,因此可以添加任何信息上去:
+展开
-ActionScript
// 存储username值给example共享对象
example.data.username = "Darron";

和早期版本的ActionScript不同,现在不能直接把属性值赋值给共享对象本身了,如果这样做了编译器会直接报错:
+展开
-ActionScript
example.variable = "This will cause a compile-time error.";

另外,直接把值赋值给data属性也不正确:
+展开
-ActionScript
example.data = "This will cause another compile-time error.";

正确的写法应该这样:
+展开
-ActionScript
example.data.variable = "This is the correct way to store data.";

可以直接存储ActionScript原生数据类型:
+展开
-ActionScript
example.data.exampleArray = new Array( "a""b""c" );
example.data.exampleDate = new Date();
example.data.exampleObject = { key1: "example", key2: -12, key3: null };

但需要注意的是,不能存储可视化对象(例如MovieClips,Sprite,Buttons,TextFields)

加支付宝好友偷能量挖...


评论(0)网络
阅读(80)喜欢(0)flash/flex/fcs/AIR