Prev | Current Page 267 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


class Main
{
static function main()
{
var p : Contact = cast new Person();
p.name = ???John Doe???;
p.telephone = ???123456???;
}
}
class Person
{
public var name : String;
public function new() { }
}
typedef Contact = { >
Person,
telephone : String
}
Class instances in Flash 9 cannot be dynamically augmented (adding fields at run time) unless they also
implement Dynamic.
134
Part I: The Core Language
Extensions applied to typedef have exactly the same structure:
typedef Color = {
r: Int,
g: Int,
b: Int
}
typedef AlphaColor = { >
Color,
a: Int
}
All the objects of type AlphaColor are of the type Color , too; in this aspect typedef extensions are very
similar to the standard class inheritance where an instance of a derived class is also an instance of the
parent class.
Enum
Almost every other language implements a form of enumeration as a way of defining a list of fixed
symbols. In haXe this functionality is provided using the enum syntax. Usually in other languages
enumerations are mapped to some numeric integer value.


Pages:
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279