Prev | Current Page 280 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

hx file using the import statement.
// content of file Main.hx
import geom.Point;
class Main
{
static function main()
143
Chapter 6: Organizing Your Code
{
var p = new Point3D(1,2,3);
// ...
}
}
The complete name geom.Point3D can also be used. Complete names are convenient to disambiguate
when the same type name is present in different packages and they are both used in the same file
context.
Enum and Packages
Enum constructors behave exactly as the other types with the exception that in a switch statement, it is
possible to use just the constructor name in place of the complete one, if the type is known at compile
time and even if the enum file has not been imported.
// content of file style/FillKind.hx
package style;
enum FillKind
{
Solid(rgb : Color);
Gradient(startColor : Color, endColor : Color);
Texture(fileName : String);
}
The enum in the preceding code can be used in the Main.hx as follows:
// content of file Main.hx
import style.FillKind;
class Main
{
static function main()
{
var c = Texture(???filename.


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