Reputation: 467
I have a class like this
package test{
class Test{}
}
class TestInnerClass{}
I can access the TestInnerClass from Test class but I need to access the TestInnerClass(as class, not its instance) from other class as well. And I don't really want to make TestInnerClass an independent class as all it contains are a few variables.
Is there any way to access the class from outside Test class?
[edit] More specifically, I need the access for the following code to work.
registerClassAlias("TestInnerClass",TestInnerClass);
Upvotes: 1
Views: 1338
Reputation: 3706
If you wanted to make a class visible outside of it's containing package your class would be defined as so:
// SampleCode.as file
package samples{
public class SampleCode {}
}
// CodeFormatter.as file
package samples{
class CodeFormatter {}
}
The SampleCode class is visible whilst the CodeFormatter class is not.
Hope I've answered your question
Upvotes: 1
Reputation: 15955
If you have a class that would not otherwise be accessed except internally by a public class you may define it as internal.
Internal classes are visible to references inside the current package.
In your example, TestInnerClass
is only visible to Test
.
Otherwise, to access the class or register class alias it must be defined public in its own .as file.
Packages help to order and classify code in hierarchy. Often, I'll keep Value Object or Data Transfer Objects within their own package, such as:
com.jasonsturges.model.vo
This helps to group smaller model classes together.
Upvotes: 1