// test for class loading cl <- FlashClassLoader(); cl.load("SampleLib.swf"); while (cl.status == "loading") { suspend(); } Test <- cl.getClass("Test"); if (Test) { print(Test().test() + "\n"); } else { print("failed to load SampleLib\n"); } // register Flash class to Squirrel class Shape <- getFlashClass("flash.display.Shape"); SimpleButton <- getFlashClass("flash.display.SimpleButton"); URLRequest <- getFlashClass("flash.net.URLRequest"); Loader <- getFlashClass("flash.display.Loader"); /** * Recatangle */ class Rect extends Shape { /** * @param x disp X * @param y dips Y * @param w width * @param w height * @param color paint color */ function constructor(x,y,w,h,color) { Shape.constructor(); graphics.lineStyle(0,color); graphics.beginFill(color); graphics.drawRect(0,0,w,h); graphics.endFill(); this.x = x; this.y = y; ::getStage().addChild(this); } function destructor() { ::getStage().removeChild(this); } } /** * Circle */ class Circle extends Shape { /** * @param x disp X * @param y disp Y * @param r radius * @param color paint color */ function constructor(x, y, r, color) { Shape.constructor(); graphics.lineStyle(0,color); graphics.beginFill(color); graphics.drawCircle(0,0,r); graphics.endFill(); this.x = x; this.y = y; ::getStage().addChild(this); } function destructor() { ::getStage().removeChild(this); } } /** * image button */ class Button extends SimpleButton { /** * create image * @param filename image filename * @return image */ function createImage(filename) { local loader = Loader(); loader.load(URLRequest(filename)); return loader; } /* * @param x disp X * @param y disp Y * @param image image basename ("image" -> "image_o.png", "image_n.png" ) */ function constructor(x, y, image) { SimpleButton.constructor(); local over = createImage(image + "_o.png"); local normal = createImage(image + "_n.png"); upState = normal; overState = over; downState = over; hitTestState = over; this.x = x; this.y = y; addEventListener("mouseDown", createFlashFunction(onMouseDown)); ::getStage().addChild(this); } function destructor() { ::getStage().removeChild(this); } function onMouseDown(event) { print("button down!\n"); } } local button = Button(200,10,"button"); local rect = Rect(400,300,60,60,0xff0000); local circle = Circle(400,300,30,0xffff00); while (true) { local tick = getCurrentTick(); rect.x = 400 + 200*sin(2 * PI * tick / 1000); circle.y = 300 + 200*sin(2 * PI * tick / 1000); suspend(); };