swf2js.js is a JavaScript FlashPlayer emulator that analyzes SWF files of Adobe Animate (Flash) in real time and converts them to HTML.
The current version is 1.2.7.
Added support for sounds and (multiple) soundstreams and synchronisation of sound and animation.
Added support for external acces/control (functions: play, step stop, showInfo, ShowDebug).
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
This is version of swf2js is based on the free version of swf2js.js (version 0.7.24) from Toshiyuki Ienaga (see https://github.com/ienaga/swf2jsa> or https://github.com/ienaga/swf2js).
For the source of this version of swf2js see https://github.com/music4classicalguitar/swf2js.
<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>
Example with callback function
Multiple swf-files in one page
If you want more control, use:
var swf = swf2js.load('your swf-file', {...your options...});
after which you can use:
Functions | Description |
---|---|
swf.play() | Start playing |
swf.stop() | Stop playing |
swf.step() | Advance one frame |
swf.showInfo() | Show info about the current swf-file |
swf.showDebug() | Show swfdump-alike info about the current swf-file (only if option debug: true) |
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:
use 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