2007年6月1日星期五

Namespaces: Name Qualifier Operator (::)

When you want to access a class member in a namespace, you need to reference that member through the namespace in which it was defined. One way to do this is through the name qualifier operator (name qualifier operator).

The name qualifier operator takes the form of two colons that connects the namespace with the member of the class you are trying to access that exists within that namespace, eg. namespace::member. Ex:

ActionScript Code:

package {

public class UsingNameSpaces {

public namespace company = "http://www.example.com/company";
public namespace individual = "http://www.example.com/individual";

company var value:
int = 10;
individual var value:
int = 2;

public function UsingNameSpaces(){
company::showValue();
// traces 10
individual::showValue();
// traces 2
}

company function showValue() {
trace(company::value);
}

individual function showValue() {
trace(individual::value);
}
}
}


Note that even though showValue is being called within the namespace, the namespace is still needed to reference variables (or other members) in namespaces used within the function body.

0 评论: