如何验证 SharedObject 的某些属性是否存在?换句话说,我想确保我从本地 SharedObject 中读取了一些有意义的内容(第一次加载 swf 时不应该得到任何好的东西),
我将从 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html< /a>
假设我
var my_so:SharedObject = SharedObject.getLocal("superfoo");
现在定义了,如果我已经在 my_so.data.foobar 下得到了一些东西,我想在我的应用程序中使用它。 (myapp.myfoo 在此之前已经有默认值)
if (my_so.data.foobar != null) myapp.myfoo=my_so.data.foobar;
这似乎挂在 Flash 10.1 上。我缺少什么?
编辑:感谢您的帮助,问题已解决。 :)
不过,如果能看到对 SharedObject 进行这种检查的惯用方式,那就太好了。我发现了很多教如何使用 SharedObject 的示例,但它们似乎掩盖了这样一个事实:您需要检查是否在其中保存了任何有价值的内容。这正是第一次加载 .swf 时发生的情况。另一个问题是检查是否成功实例化 SharedObject(例如,当它被禁用时),但这将是另一个问题......
How do I verify that certain properties of SharedObject exist? In other words, I want to make sure I read something sensible from my local SharedObject (one should not get anything good the first time loading swf )
I am going from information found on http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html
Let's say I define
var my_so:SharedObject = SharedObject.getLocal("superfoo");
Now, if I have already gotten something under my_so.data.foobar I would like to use it in my application. (myapp.myfoo already has a default value before this)
if (my_so.data.foobar != null) myapp.myfoo=my_so.data.foobar;
This seems to hang on Flash 10.1 . What am I missing ?
EDIT: Thanks to your help the issue is fixed. :)
However, it would be nice to see the idiomatic way of doing this kind of check for SharedObject. I've found many examples teaching how to use SharedObject but they seem to gloss over the fact that you need to check whether you saved anything worthwhile in it. That is exactlyl what happens on loading .swf the first time. Another issue would be checking whether one successfully instantiated SharedObject (for example, when it is disabled), but that would be a whole another question...
发布评论
评论(2)
我怀疑您遇到了 null 与 undefined 问题。
我会尝试使用 hasOwnProperty 方法
:有几种方法可以确定对象是否具有特定属性,但 hasOwnProperty() 可能是最好的方法。
I suspect you are running into the null vs undefined issue.
I would try using the hasOwnProperty method:
There are several methods for determining whether an object has a particular property, but hasOwnProperty() is probably the best way to do it.
我更喜欢:
I prefer: