Skip to content

Play an AIR application in a page

The element also plays an AIR application from its package (.air), a ZIP of its folder, or the files of one. openAirApp finds the descriptor: the package’s META-INF/AIR/application.xml, or else the shallowest *-app.xml. loadAir then plays its content SWF under AIR’s API and the application sandbox, as adl does:

import { openAirApp } from "@swf2es/web";
const response = await fetch("/games/MyGame.air");
const app = openAirApp(new Uint8Array(await response.arrayBuffer()));
const movie = document.querySelector("swf2es-player");
movie.addEventListener("airexit", (e) => console.log("exit", e.detail.code));
await movie.loadAir(app, { arguments: ["--level", "3"] }); // InvokeEvent's arguments

The application’s files are held in memory. File sees them under its directory, FileStream reads them (at once, or over frames with openAsync), app: and file: URLs into it load from there, and any other URL goes to the network as a page’s would. Its own directory is read-only, as an installed application’s is. What it writes elsewhere, in its storage directory (app-storage:) or the user’s directories, is kept in the browser’s IndexedDB by the application’s id, and is there the next time the page plays it; loadAir(app, { keepFiles: false }) keeps it in memory alone, for that play. File.createTempFile() and File.createTempDirectory() make theirs in its cache directory (File.cacheDirectory, /cache), kept the same way until it deletes them, as AIR leaves them for the application to delete. EncryptedLocalStore keeps its items in IndexedDB too, by the application’s id: a page has no keychain to encrypt them by, and the browser keeps them as it keeps the site’s other data. The element is its one window, at the descriptor’s size, and flash.display.Screen has the one screen the page is on (window.screen); the play page opens .air and .zip files too.

A URLLoader or URLStream whose response tells an HTTP error (404, 500) gets the response’s body in an AIR application, here and in the desktop app, as in AIR: with a listener for httpResponseStatus added before load, the load completes, the body its data; without one it ends in ioError, the body in data all the same. A SWF that is no AIR application gets ioError and no data, as in Flash Player.

A SWF played on its own that names a class only AIR has, such as NativeApplication or File, plays as an AIR application too: the browser’s Flash Player would refuse it (VerifyError #1014). Its directory holds it alone, and its app: URLs load any other file from beside it on the server.

The desktop app runs an AIR application from its descriptor on disk instead, with the real file system, sockets, WebSockets and the network, as adl runs one:

Terminal window
npx @swf2es/desktop app.xml [root-dir] [-- arguments...]

The descriptor’s first window’s content SWF plays from app:/, at the descriptor’s size and with its title; the arguments after -- reach its InvokeEvent, and flash.display.Screen has the system’s displays, their colorDepth counted as AIR counts it (32 for true colour, where the system says 24). File › Open, or a descriptor dropped on the window, runs the application too, from its own directory; the app asks first, as an application reaches your files and the network unasked.