Prev | Current Page 303 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

hx for Flash 7/8
import flash.Lib;
import flash.MovieClip;
import flash.MovieClipLoader;
class Main
{
public static function main()
{
#if flash7
var movie = ???f7.swf???;
#else flash8
var movie = ???f8.swf???;
#end
var loader = Lib.current.createEmptyMovieClip(???loader???, 0);
var ml = new MovieClipLoader();
ml.onLoadInit = function(mc : MovieClip) : Void
{
var drawer = Type.createInstance(mc.Drawer, [Lib.current]);
draw(drawer);
};
ml.loadClip(movie, loader);
}
private static function draw(drawer : Dynamic)
{
drawer.drawRect(20, 20, 80, 100);
drawer.drawPoly([[120, 10], [170, 100], [ 70, 100], [120, 10]]);
}
}
The version 7 and 8 are functionally equivalent in this case; conditional compilation is just used to
select the corresponding file for each version. The MovieClipLoader permits a much cleaner code syntax,
and managing errors can be easily introduced adding a declaration for the ml.onLoadError function.
The draw function works the same as for version 6:
// content of file Main.


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