Using Namespaces Issues August 26, 2007
This article on Kirupa is good example on how Namespaces are normally used both in the 'use namespace' and "::" syntax
Namespaces and inheritance
So after beating my head for a full day. Namespaces + inheritance + describeType don't play together, this sucks as now I have to make everything public which breaks encapsulization. Take this:
public class NameSpaceTest extends IntrospectableObj{
public function NameSpaceTest(){
super();
use namespace COG;
var desc:XML = describeType( this);
// var desc:XML = flash.utils.describeType( hsm);
trace(" RESULT TREE2 \r" +desc.toString().split(">").join("").split("<").join(""));
}
COG function s_COGS_INTROSPECTABLE():void{
trace("Hello World from introspectable::s_introspectable");
}
public function NAME_SPACE_TEST_FUNCTION():void{}
}
DESCRIBE TYPE OUTPUTS:
method name="NAME_SPACE_TEST_FUNCTION" declaredBy="com.troyworks.cogs::NameSpaceTest" returnType="void"/
method name="s_COGS_INTROSPECTABLE" declaredBy="com.troyworks.cogs::NameSpaceTest" returnType="void" uri="COGS"/
All good. You can see it's outputting a customname spaced item. As soon as you extend from any other class that also uses that namespace your custom namespaced items drop off of describeType, though public functions still show up:
type name="com.troyworks.cogs::NameSpaceTest" base="com.troyworks.cogs::IntrospectableObj" isDynamic="false" isFinal="false" isStatic="false"
extendsClass type="com.troyworks.cogs::IntrospectableObj"/
extendsClass type="Object"/
method name="NAME_SPACE_TEST_FUNCTION" declaredBy="com.troyworks.cogs::NameSpaceTest" returnType="void"/
variable name="pubVar" type="Function"/
method name="s_public" declaredBy="com.troyworks.cogs::IntrospectableObj" returnType="void"/
method name="getNS" declaredBy="com.troyworks.cogs::IntrospectableObj" returnType="Namespace"/
You can inherit from non-namespace users (e.g. Array). I would classify this as a bug, so I've logged it.
Function Pointers and Namespaces
for public non-namespaced items you can call a function via
var methodName:String = "someFunction";
this[ methodName]();
for namespaced functions this will throw a runtime error, you'll need to specify the namespace like
this:COG[methodName]();

Add a Comment: