views:

711

answers:

3

Tutorials usually don't deal with scope in Actionsript. Can you point me to some documentation and/or explain what should I know about it. I want to avoid problems arising from certain classes are not visible at cretain places.

+1  A: 

You're a bit vague, but hopefully I'm getting you ;)

Scope for classes are generally pretty easy to handle, it mostly comes down to packages. Packages are created in a simple tree structure, and in ActionScript3 the filestructre has to follow the namespaces. Which makes it even easier.

You can access any class from anywhere, but if it's in another package you will need to "import" the class. This is done by writing an import statement in the beginning of class or interface where you need to use it. Like so:

import flash.display.MovieClip;

There is an exception to this rule, a class can be declared with the internal keyword, in which case the class will only be available within that package. This is mostly used for helper classes.

Basicly you should not worry about classes not being available.

NB: You create package with the package keyword.

Lillemanden
To make this post correct you need replace every instance of the word "namespace" with the word "package" and change "will only be available within that class" to "will only be available within that package". As is the info is quite incorrect though :( Also the flash package is not capitalized.
Bryan Grezeszak
Corrected it, except the package->namespace. Just because Actionascript uses the package keyword doesn't mean it's anything else but namespaces.
Lillemanden
Except that there is namespace functionality in AS3, and it is not the same as package functionality. Therefore using the words package and namespace interchangeably in AS3 is not correct, and misleading.
Bryan Grezeszak
I hate to admit it, but you are absolutely right. First i thought you where refering to namespaces in XML. But I googled it, and I do remember reading about it long time ago, but I never used it. Totally forgot about it. Seems like an odd choice of words considering other languages.
Lillemanden
A: 

Hi, I have a more specific question in the same realm. I have a document class with variable A. I have a class that is instantiated in the doc class that lives in a different folder. In this attached class, I try to reference variable A through the doc class but get an error:

Property A not found on MainDoc and there is no default value.

I have the class imported properly on the Doc class and I even imported the doc class in the attached class. The interesting thing is if I move the attached class to the same folder as the doc class I don't get the error and the attached class can now reference variable A.

Why would I be required to have a class in the same folder if I want to reference the contents of another class? Is there a step I'm missing?

john