View comments | RSS feed

1.8 Packages

Packages in ActionScript are very similar to packages in Java and namespaces in C# and C++. Packages are useful for organizing frameworks (or toolkits, or APIs) into sets of related definitions: classes, namespaces, interfaces, functions, and variables.

Client code can import all or parts of a package to access the functionality it provides without cluttering its global namespace with unneeded names. In the following example, the import directive makes the class Greeter visible to the global code that contains the import directive.

package actors {
    public class Greeter {
        public function hello() { 
            trace("hello, world")
        }
    }
}
import actors.Greeter
var greeter : Greeter = new Greeter
greeter.hello()

Comments


Constantiner said on Mar 2, 2006 at 11:42 AM :
Code example
var greeter : Greeter = new Greeter
calls constructor without (). Is it best practice and why? Or maybe there is an error in example?
Francis Cheng said on Mar 6, 2006 at 2:41 PM :
It is not necessarily a best practice to omit the parentheses when using the new operator, but it is legal to do so. Tthis is also true in previous versions of ActionScript and in the ECMAScript standard.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification10.html