swf2js

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.


Content


Basic usage

<script type="text/javascript" src="swf2js.js"></script>
<script type="text/javascript">
    swf2js.load('SET SWF PATH');
</script>  
		

Options

OptionDescription
tagIdPlace swf-player in element with tag 'tagId'
widthSet width of swf-player
heightSet height of swf-player
callbackFunction 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"
bgcolorSet background color
autoStarttrue: 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>

Examples

Examples

Example with callback function

Animated music

Multiple swf-files in one page


Advanced usage

If you want more control, use:

var swf = swf2js.load('your swf-file', {...your options...});

after which you can use:

FunctionsDescription
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();
});

Testbed

To test with your own SWF-files:
use testbed.html


Alternative

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.


Known problems


Tools

Useful tools to analyze SWF-files are:


Information

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