swf2js.js is a JavaScript FlashPlayer emulator that analyzes SWF files of Adobe Animate (Flash) in real time and converts them to HTML.
This version of swf2js is an adaption based on swf2js.js version 0.7.24 from https://github.com/ienaga/swf2js.
swf2js.min.js is the minified version created with Google Closure Compiler.
For the source of swf2js see https://github.com/music4classicalguitar/swf2js.
Added support for sounds and soundstreams and synchronisation of sound and animation
Warning : no support for Actionscript 3 which is introduced in Flash Player 9 (initially called 8.5).
Newer swf-files (version 9 and up) will probably still work, if you didn't useActionscript 3
See https://github.com/swf2js/swf2js and https://swf2js.com/en/ for a commercial version that supports Actionscript 3.
See also https://swf2js.com/en/#skills for the differences between the free and the commercial version.
<script type="text/javascript" src="swf2js.js"></script> <script type="text/javascript"> swf2js.load('SET SWF PATH'); </script>
Option | Description |
---|---|
tagId | Place swf-player in element with tag 'tagId' |
width | Set width of swf-player |
height | Set height of swf-player |
callback | Function to be called when swf-player has loaded the swf-file |
FlashVars | |
quality | "low": 0.25, "medium": 0.8 (default), "high": 1.0 |
audioType | "webaudio" (default), "webmedia", "html5", "audio" |
bgcolor | Set background color |
autoStart | true: start animation, false: don't start animation (show a button to start) |
quality: for mobile devices default 0.6.
audioType: default depending on what is supported by your browser.
autoStart: depends on whether the swf-file contains sounds and/or video and whether autoplay of audio and/or video is allowed.
Example usage of options.
<div id="swf_1" style="width: 320px; height: 320px;"></div> <div id="swf_2" style="width: 320px; height: 320px;"></div> <script type="text/javascript" src="swf2js.js"></script> <script type="text/javascript"> swf2js.load('analog20.swf', {tagId: "swf_1", width: 320, height}); swf2js.load('mogura.swf', {tagId: "swf_2"}); </script>
Example with a callback function:
<script>function informMe(arg) { alert("informMe : swf-file loaded"); } swf2js.load('tiger.swf', { "tagId": "swf_instance", "width": "320", "height": "320", "autoStart" : true, "callback" : informMe, "bgcolor": "black" }); </script>
If you want more control, use:
var swf = swf2js.load('your swf-file', {...your options...});
after which you can use:
Functions | Description |
---|---|
play() | Start playing |
stop() | Stop playing |
step() | Advance one frame |
showInfo() | Show info about the current swf-file |
Example: if you have a button with id='play':
document.getElementById('play').addEventListener('click', function(e) { swf.play(); });
To test with your own SWF-files:
try testbed.html
An alternative for swf2js is Ruffle (see also github).
Try it here on testbed_ruffle.html for ruffle (nightly.2025.3.21) or on the demo on https://ruffle.rs.
You can see the same example Animated music with ruffle instead of swf2js.
Useful tools to analyze SWF-files are:
See SWF FILE FORMAT SPECIFICATION VERSION 19 on https://open-flash.github.io/.
If you have (or can find) Flash MX 2004 or Flash (Professional) 8, you can stil create sfw-files and use them with swf2js.js