2011-02-25 158 views
2

我在flex的ActionScript类中发现了这个。在flex中声明变量

protected::valueMin 

请让我知道这是什么意思。在一开始,我没有看到任何类型的声明。 我是flex中的新手。

回答

2

正如spash说,这句法用于命名空间。在这种情况下,它实际上用于解决编译器问题。问题是你不能声明一个访问器,其中getter与setter具有不同的范围。也就是说,你可以声明它,但通过它的名字访问访问器会导致编译错误。

考虑以下几点:

private var _name:String; 

[Bindable(event="nameChange")] 
public function get name():String { 
    return _name; 
} 

private function set name(value:String):void { 
    if (value !== _name) { 
    _name = value; 
    dispatchEvent(new Event("nameChange")); 
    } 
} 

如果现在尝试访问“名称”属性来获取或设置,这将导致编译错误:

name = "John Doe"; 

但是,如果您指定代码将编译的范围。

private::name = "John Doe"; 
+1

现在不应该使用'name =“Jon Skeet”''吗? ;-) – splash 2011-02-25 22:42:39

+0

呵呵,的确如此。我发誓我从现在开始做。 – 2011-02-26 05:57:02

+0

:)谢谢吨飞溅和Christophe。 – 2011-03-03 05:01:02

1

它应该是对受保护的类成员valueMin的引用。

You can reference namespaces with the use namespace directive or you can qualify the name with the namespace using the name qualifier (::) punctuator.

还看到:Namespaces