开发者

Flash AS3 - Internal namespace modifier

I am working on a library that I wish to hide the internals of to the outside world.

I figured I can use 'internal class' where ever I wanted to hide the class,

How ever to my understanding, declaring a class in namespace test.NS1 means it can only access classes defines in test.NS1 and nothing else.

For example,

(both in the same library)

/src/NS/test.as - internal class
/src/NS/test2/test2.as - internal class

test / test2 cannot see each other. Am I missing something here? or is there no proper way to hide my internal classes yet let t开发者_运维问答hem talk within the library ?


The namespace "internal" restricts access to classes defined within the same package. Therefore, a class com.mycompany.app.Foo can see the internal class com.mycompany.app.Bar, but not com.mycompany.app.data.Baz.

See http://www.adobe.com/livedocs/flex/201/langref/statements.html#internal


For future reference.

Yes you can hide your classes with internal namespaces! You can create a different namespace in each sub package, all pointing to the same URI.

for example:

com.mycompany.app internal namespace foo = "yourcompany.com/as3/namespaces/internal_yourcompany"

com.mycompany.app.data internal namespace foo_data = "yourcompany.com/as3/namespaces/internal_yourcompany"

foo and foo_data will be the same namespace, but in a different package. I found this explanation here

For the visibility of properties, all that matters is the uri. You can define two namespaces with a different name in two different packages. As long as they contain the same uri, they will refer to the same property.

namespace aNs = "myUri";
namespace bNs = "myUri";

class MyClass {
  aNs var foo: String;
}

var instance: MyClass = new MyClass();
instance.aNs::foo; // works as expected
instance.bNs::foo; // works too

var cNs: Namespace = new Namespace( "myUri" );
instance.cNs::foo; // works as well
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜