Prev | Current Page 304 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

hx for Flash 9
import flash.Lib;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
class Main
{
static var c : Int;
public static function main()
{
var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
function(event : Event) : Void
{
var cl = event.currentTarget.applicationDomain.getDefinition(???Drawer???);
var drawer = Type.createInstance(cl, [Lib.current]);
draw(drawer);
});
(continued)
156
Part I: The Core Language
loader.load(new flash.net.URLRequest(???f9.swf???));
flash.Lib.current.addChild(loader);
}
private static function draw(drawer : Dynamic)
{
drawer.drawRect(20, 20, 80, 100);
drawer.drawPoly([[120, 10], [170, 100], [ 70, 100], [120, 10]]);
}
}
The Flash 9 platform has changed a lot from the previous versions; functionalities have been broken
apart into many smaller classes, and packaged in areas that are more specific. The code uses many more
classes and instances but it is easier to read and debug. In this example, a Loader instance is used to
load the external library, and the URL to the external movie clip must be wrapped in a URLRequest
object.


Pages:
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316