Skip to content

SWF loader for OpenFL projects built with Webpack

License

Notifications You must be signed in to change notification settings

openfl/swf-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SWF Loader for Webpack

Generates an asset library from a .swf file that may be loaded by OpenFL.

Usage

Install this swf-loader module into your Webpack project using the following command.

npm install --save-dev swf-loader

Then, in your webpack.config.js file, add the following rule to allow .swf files to be imported using swf-loader.

module: {
	rules: [
		{ test: /\.swf$/, loader: 'swf-loader' }
	]
}

Finally, import a .swf file and load it using the openfl.utils.AssetLibrary class.

import Sprite from "openfl/display/Sprite";
import AssetLibrary from "openfl/utils/AssetLibrary";
import myLibraryPath from "./assets/myLibrary.swf";

class MySprite extends Sprite {
	constructor() {
		super();
		AssetLibrary.loadFromFile(myLibraryPath)
			.onComplete((library) => {
				const mc = library.getMovieClip("MyAnimation");
				this.addChild(mc);
			})
			.onError(e => console.error(e));
	}
}