Given this:
public namespace foo;
foo var bar:String = "baz";
We can access the property “bar” like so:
var ns:Namespace = foo;
trace(ns::["bar"]);
This doesnt work however:
var ns:Namespace = new Namespace("foo");
trace(ns::["bar"]);
It gives me the following error:
ReferenceError: Error #1069: Property foo::bar not found on MyClass and there is no default value.
On further inspection of the foo namespace I can see (in the debugger) that the URI is in the format {package}:{type}/{name}. If I try to replicate this by doing the following:
var ns:Namespace = new Namespace(getQualifiedClassName(this).replace("::", ":") + "/foo");
trace(ns::["bar"]);
(drumroll)
Still no dice.
Additionally I’ve tried the following combinations without luck:
var ns:Namespace = new Namespace(null, getQualifiedClassName(this).replace("::", ":") + "/foo");
var ns:Namespace = new Namespace("", getQualifiedClassName(this).replace("::", ":") + "/foo");
Does anyone know if it is possible to get access to namespaced members like this? I don’t have compile time access to the namespace, but I can look up it’s uri (and prefix) dynamically at run time.
Edit 2:
Ok the problem here is that when you create a namespace the compiler create it with the flag package internal, or you have no way in as3 to create a namespace with different access flag (public, protected,…)
So if your namespace is declared public you can get it using the function getDefinition.
Here an example of function that parse your uri and give you back your namespace whereever it is declared in a file or in a class
or
Here an example of a function that give you the namespace from the uri
Usage :
Edit:
Ok i missread you have a proplem with a dynamic Namespace name not dynamic property name :
So you can access to your created namespace by a static call to your namespace name from the class where it is defined:
So for your example it’s:
i have updated the wonderfl example : http://wonderfl.net/c/7M9O
You can create a new QName with your custom namespace and your dynamic name, then access the property with this[myQName] :
Here the live example on wonderfl : http://wonderfl.net/c/7M9O