Skip to main content
barpos
Known Participant
February 14, 2011
Answered

Confused about AS files

  • February 14, 2011
  • 2 replies
  • 1239 views

Hi,

I'm using an .AS file to store a custom used-defined class (extending an existing class or not).  I have no problem with that, but how about when I store MANY classes in the same .AS file?  I understand I need to make the .AS file as part of a [custom] package.  If I understand the manual correctly, one can only make use of one instance of the Public specifier within an .AS file (or is it the package itself?), therefore only one class can be accessible externally.  Correct?  If so, one must define a custom namespace that would be applied to properties and methods within the classes written in the packaged .AS file.  Am I lost here??  So, instead of referencing the enclosed methods/properties via a class name, I'd do it via the custom namespace { example, mynamespace::myMethod(); }  Correct?

Regards,

Ron

This topic has been closed for replies.
Correct answer FeZEC

Not many advanced users utilize custom namespaces either.

2 replies

Participating Frequently
February 16, 2011

An as file is a way to declare an external definition.  The path of the class becomes the qualified name, and is how the compiler reaches the internal contents of the as file.  The term namespace represents the scope visibility of something.  It can be a class, a method even a variable.  Consider if you had two methods with the same name, the only way the player knows which one to reach is determined by the qualified name.

barpos
barposAuthor
Known Participant
February 16, 2011

>The term namespace represents the scope visibility of something<

Yes, just like the Public, Private, Internal, ect, modifiers.  So, why getting into a custom namespace, especially as a novice?

FeZECCorrect answer
Participating Frequently
February 16, 2011

Not many advanced users utilize custom namespaces either.

kglad
Community Expert
Community Expert
February 14, 2011

no, only one class can be accessed externally (from outside your classes).  the other classes can only be accessed from each other and the externally accessible class.

barpos
barposAuthor
Known Participant
February 14, 2011

Then, I don't have a clue what the namespaces are.  I thought they said it was to make variables and properties visible?

I presume that if I want to be able to access many custom classes, I'd have to write several .AS file, but declaring all of them with the same custom package.  Right?

Ron

February 15, 2011

Yes, you should write several classes in seperate AS files and make them part of the same package.

I belive however that you can specfiy additional private helper classes in the same AS file as a public class if they outside the package decleration.

This helper classes are visible only to the primary class in the package block or other helper classes in the same file.

Consider:

package  {

import flash.display.MovieClip;

public class MyClass extends MovieClip {

public function MyClass() {

// constructor code

trace('myclass');

var test:MyHelper = new MyHelper();

}

}

}

class MyHelper {

function MyHelper() {

var helper:HelpersHelper = new HelpersHelper();

}

}

class HelpersHelper {

function HelpersHelper () {

trace('test helpers helper');

}

}

As for namespaces perhaps this link will help: http://gskinner.com/blog/archives/2010/01/a_complete_guid.html