Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:30:54+00:00 2026-05-25T09:30:54+00:00

Given this: public namespace foo; foo var bar:String = baz; We can access the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:30:54+00:00Added an answer on May 25, 2026 at 9:30 am

    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

    package XXX {
     public namespace foo;
    }
    

    or

    package YYY {
     class XXX {
      public namespace foo2;
     }
    }
    

    Here an example of a function that give you the namespace from the uri

        public function getNamespaceFromURI(uri:String, domain:ApplicationDomain = null):Namespace {
            if(domain == null) domain = ApplicationDomain.currentDomain;
    
            var tmp:Array = uri.split("/");
            var ns:Namespace = null;
            var pkg:String = tmp[0].replace(":", ".");
            if(tmp.length == 1) {
                // namespace declared in a file
                ns = domain.getDefinition(pkg) as Namespace;
            } else {
                // namespace inside a class
                var cls:Class = domain.getDefinition(pkg) as Class;
                if(cls) {
                    ns = cls[tmp[1]] as Namespace;
                }
            }
            return ns;
        }
    

    Usage :

    var ns:namespace = getNamespaceFromURI("YYY:foo");
    // or
    var ns:namespace = getNamespaceFromURI("YYY:XXX/foo2");
    

    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:

    class X {
     public namespace foo;
    }  
    
    var ns:Namespace=X['foo'];
    

    So for your example it’s:

    public namespace foo;
    foo var bar:String = "baz";
    
    var ns:Namespace=MyClass['foo'];
    trace(ns::['bar'])
    

    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] :

    var ns:Namespace=foo;
    var qn:QName=new QName(foo, 'bar');
    trace(this[qn]);
    

    Here the live example on wonderfl : http://wonderfl.net/c/7M9O

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a struct like this: public struct SomeStruct { public SomeStruct(String stringProperty, Int32 intProperty)
Given this Global.asax.cs: using System; using System.Web; namespace Foo.Web { public class Global :
Given this object class Contact { public IEnumerable<Person> People { get; } public string
given this code namespace GridTests { public class Grid<T> { IEnumerable<T> DataSource { get;
Given this declaration: using System; using System.Collections; using System.Collections.Generic; namespace AProject.Helpers { public static
Given this: namespace TheEntities { [DataContract(IsReference=true)] public class Question { [DataMember] public virtual int
Given this generic serialization code: public virtual string Serialize(System.Text.Encoding encoding) { System.IO.StreamReader streamReader =
Given this code public override void Serialize(BaseContentObject obj) { string file = ObjectDataStoreFolder +
Given this: Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If DateTime.Now()
Given this class public partial class Default : Page { private IRepository repo; ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.