检查Action Script中是否存在某个项目

时间:2022-11-01 00:03:12

Sorry, I've never done AS before, so I apologize for the basic question. There is a line in this file I am trying to modify:

对不起,我以前从未做过AS,所以我为基本问题道歉。我试图修改此文件中有一行:

var media:Namespace = rssXML.channel.item[i].namespace("media");

var media:Namespace = rssXML.channel.item [i] .namespace(“media”);

I'm just trying to check to see if it exists and if it has a value?

我只是想检查它是否存在以及它是否有值?

I know in PHP it would be

我知道在PHP中它会是

if(isset(rssXML.channel.item[i].namespace("media") && !empty(rssXML.channel.item[i].namespace("media")) {

if(isset(rssXML.channel.item [i] .namespace(“media”)&&!empty(rssXML.channel.item [i] .namespace(“media”)){

//Do Something

}

What would be the AS equivalent?

什么是AS等价物?

2 个解决方案

#1


if (variablename) { // it's there } else { // it's not }

#2


All AS classes extend Object which has a hasOwnProperty() test which returns a boolean if a property with the name exists. Then you can test if (property) or if (property == null).

所有AS类都扩展了Object,它具有hasOwnProperty()测试,如果存在名称属性,则返回布尔值。然后你可以测试if(property)或if(property == null)。

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Object.html#hasOwnProperty()

#1


if (variablename) { // it's there } else { // it's not }

#2


All AS classes extend Object which has a hasOwnProperty() test which returns a boolean if a property with the name exists. Then you can test if (property) or if (property == null).

所有AS类都扩展了Object,它具有hasOwnProperty()测试,如果存在名称属性,则返回布尔值。然后你可以测试if(property)或if(property == null)。

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Object.html#hasOwnProperty()