Run a SWF headless in node
import { readFile } from "node:fs/promises";import { createCodegen } from "@swf2es/codegen";import { builtinLibrary, Player, playerglobalLibrary, Scripting } from "@swf2es/player";
const wasm = await readFile(new URL(import.meta.resolve("@swf2es/codegen/codegen.wasm")));const scripting = new Scripting(await createCodegen(await WebAssembly.compile(wasm)), { print: (line) => console.log(line), // trace() realTime: null, // getTimer() follows the frames, so every run prints the same});await scripting.loadLibraries([builtinLibrary, playerglobalLibrary]);
const player = new Player(await readFile("movie.swf"), scripting);await player.start(); // the document class and the first framefor (let frame = 2; frame <= 10; frame++) { await scripting.settled(); // loads asked for in the last frame arrive player.tick();}player.destroy();Without a renderer, nothing is drawn, and BitmapData.draw of a display
object is not supported. The display list, scripts, timers, loads and
sockets all run.