验证AS3共享对象的数据属性存在 [英] Verify that property of AS3 SharedObject data exists

查看:129
本文介绍了验证AS3共享对象的数据属性存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何验证共享对象的某些特性存在吗?换句话说,我要确保我读的东西懂事从我的本地共享对象(一个不应该得到什么好东西了第一次加载SWF)

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 )

我是从的http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html

比方说,我定义

var my_so:SharedObject = SharedObject.getLocal("superfoo");

现在,如果我已经得到下my_so.data.foobar东西,我想用它在我的应用程序。 (myapp.myfoo已经在此之前有一个默认值)

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;

这似乎挂在的Flash 10.1。我在想什么?

This seems to hang on Flash 10.1 . What am I missing ?

编辑:谢谢你的帮助的问题已修复。 :)

Thanks to your help the issue is fixed. :)

不过,这将是很好看做这种检查的共享对象中的惯用方式。我发现很多例子教导如何使用共享对象,但他们似乎掩盖,你需要检查你是否保存任何有价值在里面的事实。这是exactlyl上加载的.swf第一次发生的事情。另一个问题将检查一个人是否成功的实例化共享对象(例如,当它被禁用),但是这将是一个整体另外一个问题...

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...

推荐答案

我怀疑你正在运行到零VS不确定的问题。

I suspect you are running into the null vs undefined issue.

我会尝试使用<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Object.html#hasOwnProperty">hasOwnProperty方法:

if (my_so.data.hasOwnProperty("foobar")) myapp.myfoo=my_so.data.foobar;

有几种方法用于确定对象是否具有特定的属性,但的hasOwnProperty()是可能做到这一点的最佳方式。

There are several methods for determining whether an object has a particular property, but hasOwnProperty() is probably the best way to do it.

这篇关于验证AS3共享对象的数据属性存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆