【问题标题】:Testing the object type of a parameter passed into a actionscript function?测试传递给动作脚本函数的参数的对象类型?
【发布时间】:2019-11-19 03:15:17
【问题描述】:

如何检查传递给函数的Object 是否是您所期望的?

public function writeRecord(grid:IExtendedDataGrid, record:Object):String
{

    ExternalInferface.call("alert","record " + record);

    if (record.contains("HotListItem")
    {
        //# I have found my object

    }
    else
    {
        //# Wrong type of object

    }

}

当我将对象显示到 ExternalInterface alert 调用时,它会显示以下内容...

记录 [object HotListItem]

我希望能够事先测试这种类型的对象。

【问题讨论】:

  • HotListItem 这个词从何而来?我的意思是alert() 是如何知道显示关于record 的特定文本的?知道这个问题的答案也会给你一个问题的答案......
  • 使用 is 运算符如下:if (record is HotListItem).
  • 感谢 Organis。 HotListItem 是一个自定义类。我尝试了“record instanceof HotListItem”并且它有效,但说它已被弃用并提示我改用“is”。

标签: actionscript-3 flash actionscript


【解决方案1】:

使用 is 运算符解决了我的问题。 我尝试了 instanceof 运算符,但这被标记为已弃用。

感谢Organis

if (record is HotListItem)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 2013-09-21
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2021-06-29
    相关资源
    最近更新 更多