{"id":24922,"library":"as2wasm","title":"as2wasm - Apache Royale Actionscript to WebAssembly Transpiler","description":"as2wasm is an Apache Royale tool that transpiles Actionscript (AS3) source code directly to WebAssembly (Wasm) modules. Version 0.1.5 is the latest stable release, part of the Apache Royale 0.9.x series. It enables running legacy Flash/Actionscript applications in modern browsers without the Flash plugin, targeting WebAssembly for near-native performance. Key differentiators: it is the only open-source AS3-to-Wasm transpiler, integrates with the Apache Royale framework for cross-platform UI compilation, and supports both ActionScript 3 and optional SWF input via a separate binary variant. Release cadence follows Apache Royale's quarterly releases.","status":"active","version":"0.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/apache/royale-asjs","tags":["javascript","apache","royale","as2wasm","webassembly","actionscript","as"],"install":[{"cmd":"npm install as2wasm","lang":"bash","label":"npm"},{"cmd":"yarn add as2wasm","lang":"bash","label":"yarn"},{"cmd":"pnpm add as2wasm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"as2wasm depends on the Apache Royale compiler for parsing and generating intermediate code.","package":"apache-royale-compiler","optional":false},{"reason":"Binaryen is used for WebAssembly optimization and validation.","package":"binaryen","optional":false}],"imports":[{"note":"as2wasm is ESM-only; require() will not work. Use dynamic import or esbuild bundler.","wrong":"const transpile = require('as2wasm').transpile;","symbol":"transpile","correct":"import { transpile } from 'as2wasm'"},{"note":"Compiles a single .as file to Wasm bytes.","symbol":"compileFile","correct":"import { compileFile } from 'as2wasm'"},{"note":"Default export is not available; use named import.","wrong":"import compileString from 'as2wasm';","symbol":"compileString","correct":"import { compileString } from 'as2wasm'"},{"note":"Exports package version string for runtime checks.","symbol":"version","correct":"import { version } from 'as2wasm'"}],"quickstart":{"code":"import { compileFile, compileString, transpile } from 'as2wasm';\n\n// Compile a .as file to Wasm\nasync function compileAsFile(inputFile) {\n  const result = await compileFile(inputFile);\n  console.log('Wasm module size:', result.byteLength);\n  return result;\n}\n\n// Transpile inline ActionScript\nconst asCode = `\nclass HelloWorld {\n  static function sayHello():String {\n    return \"Hello from AS3 in Wasm!\";\n  }\n}\n`;\nconst wasmModule = await compileString(asCode);\n// wasmModule is a Uint8Array containing the Wasm binary\n\n// Instantiate and use\nconst wasmInstance = await WebAssembly.instantiate(wasmModule);\nconst sayHello = wasmInstance.exports['HelloWorld.sayHello'];\nconsole.log(sayHello()); // prints the string","lang":"typescript","description":"Demonstrates compiling ActionScript files and strings to WebAssembly modules, then instantiating them."},"warnings":[{"fix":"Install the SWF variant: npm install apache-royale-0.9.x-bin-js-swf or use the royale-asjs SWF build.","message":"as2wasm v0.1.0 removed the SWF-to-Wasm pipeline; use apache-royale-0.9.x-bin-js-swf for SWF support.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Replace calls to `compile()` with `compileString()`.","message":"The function `compile()` was renamed to `compileString()` in v0.1.3.","severity":"deprecated","affected_versions":">=0.1.3"},{"fix":"Use dynamic import (e.g., `import('as2wasm')`) in Node.js or configure your bundler for ESM.","message":"Module uses ES modules only; importing with CommonJS `require()` throws an error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use the `memory` option: `compileString(code, { memory: { initial: 256, maximum: 512 } })`.","message":"WebAssembly memory limit: AS3 strings and arrays may exceed default Wasm memory (64KB).","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Remove `-as2` or `--as2` flags in compile options; code must be AS3 compliant.","message":"v0.1.4 dropped support for ActionScript 2 compatibility flags; use AS3-only.","severity":"breaking","affected_versions":">=0.1.4"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install as2wasm` (or `yarn add as2wasm`) in your project root.","cause":"Package not installed or not in the node_modules path.","error":"Error: Cannot find module 'as2wasm'"},{"fix":"Use `compileString()` instead of `compile()`.","cause":"Using the old `compile()` function name replaced in v0.1.3.","error":"TypeError: as2wasm.compile is not a function"},{"fix":"Convert octal literals to decimal or hex (e.g., 0777 -> 511 or 0x1FF).","cause":"ActionScript code contains legacy octal literals (e.g., 0777) not supported in strict mode.","error":"SyntaxError: Octal literals are not allowed in strict mode in AS3"},{"fix":"Use ActionScript import statements: `import flash.display.Sprite;`","cause":"Used ES module import syntax inside ActionScript code (file), but transpiler expects AS3 import.","error":"Compile error: 'import' declarations may only appear at top level of a module"},{"fix":"Increase initial memory size: `compileString(code, { memory: { initial: 512 } })`.","cause":"WebAssembly memory insufficient for large ActionScript objects.","error":"Wasm runtime error: out of memory (OOM) when allocating large string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}