从动作类获取静态属性 [英] Get a static property from class in actionscript

查看:119
本文介绍了从动作类获取静态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个类

 包somePackage
{
    公共类SomeClass的
    {
        公共静态常量FOO:SomeClass的=新SomeClass的(0);
        公共静态常量BAR:SomeClass的=新SomeClass的(1);
        }
}
 

我希望能够得到那些静态属性给它的名字。

例如:

 公共静态函数的getProperty(参数propertyName:字符串):SomeClass的{
    //不知道放在这里
}

VAR property1:SomeClass的= SomeClass.getProperty(FOO); // property1 == SomeClass.FOO
变种property2:SomeClass的= SomeClass.getProperty(BAR); // property2 == SomeClass.Bar
 

解决方案

您可以使用方括号是这样的:

  SomeClass的['富']
 

或者,如果你希望把它放在一个方法返回一个类型的对象:

 公共静态函数的getProperty(参数propertyName:字符串):SomeClass的{
    返回SomeClass的[参数propertyName]
}
 

I have this class

package somePackage
{
    public class SomeClass
    {
        public static const FOO: SomeClass = new SomeClass("0");
        public static const BAR: SomeClass = new SomeClass("1");
        }
}

I want to be able to get those static property given it's name.

Example:

public static function getProperty(propertyName: String): SomeClass {
    //don't know what goes here
}

var property1:SomeClass = SomeClass.getProperty("FOO"); // property1 == SomeClass.FOO
var property2:SomeClass = SomeClass.getProperty("BAR"); // property2 == SomeClass.Bar

解决方案

You could use square brackets like this:

SomeClass['FOO'] 

Or if you want to put it in a method that returns a typed object:

public static function getProperty(propertyName: String):SomeClass {
    return SomeClass[propertyName]
}

这篇关于从动作类获取静态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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