Prev | Current Page 278 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


// content of file Main.hx
class Main
{
static function main()
{
var p = new geom.Point(5,5);
var c = new geom.Circle(p, 10);
trace(c.perimeter());
}
}
The example file ( Main.hx ) is in the root directory of project and is the entry class used by the compiler.
Because no package is declared, the class is part of the default empty package. When the previous
example is compiled, the output will contain the definition of the three classes mentioned, because all
three are used in the project; even if Point is not directly invoked by Main , Circle needs its presence to
work properly.
Explicit Import
Another way to reference definitions on different files is to explicitly state that a certain file is required.
This has two major effects: package names are no longer needed and now it is possible to reference all
the types declared in the imported file and not just the main one. The import statements are introduced
at the same level of the type and package definitions and can be positioned anywhere in the file but after
the package declaration, if such exists.


Pages:
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290