Skip to content

Embed a SWF in a page

@swf2es/web defines <swf2es-player> when it loads. It takes the same main attributes as an <embed>. The page calls configure() once, before the first player loads:

<swf2es-player id="movie" src="movie.swf" width="800" height="600"
flashvars="lang=en" scale="showAll" allowscriptaccess="sameDomain">
</swf2es-player>
<script type="module">
import { configure } from "@swf2es/web";
configure({
cache: true, // keep compiled modules in IndexedDB for the next visit
});
const movie = document.getElementById("movie");
movie.addEventListener("error", (e) => console.error(e.detail.error));
await movie.ready; // resolves once the SWF plays
</script>

The packages are ES modules, so serve them with a bundler or an import map for @swf2es/* (tests/player/serve.ts has one), the renderer’s @swf2es/player/scene, @swf2es/render/webgl and @swf2es/context3d/device among them.

configure({ libraries: { builtin, playerglobal } }) takes URLs of other ABCs to load in place of the shipped ones, each optional: a page that would rather play on Flash Player’s own playerglobal gives its URL.