Prev | Current Page 301 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

drawRect(20, 20, 80, 100);
drawer.drawPoly([[120, 10], [170, 100], [ 70, 100], [120, 10]]);
}
}
Dynamic Link
In the dynamic link option, the main class loads dynamically the swf containing the Drawer definition
and uses it to instantiate an object. The systems to load dynamically external movie clips in Flash vary a
lot with each version. It is possible to write the code in a unique file using conditional compilation but
for the sake of clarity, the example is repeated for Flash 6, Flash 7/8, and Flash 9.
// content of file Main.hx for Flash 6
import flash.Lib;
import flash.MovieClip;
class Main
{
public static function main()
{
var container = Lib.current.createEmptyMovieClip(???container???, 0);
var loader = container.createEmptyMovieClip(???loader???, 0);
container.onEnterFrame = function() {
if(loader.Drawer != null) {
container.onEnterFrame = null;
var drawer = Type.createInstance(loader.Drawer, [Lib.current]);
draw(drawer);
}
}
loader.loadMovie(???f6.swf???);
}
private static function draw(drawer : Dynamic)
{
drawer.


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