Giter Site home page Giter Site logo

swf's Introduction

MIT License Haxelib Version

SWF

Provides runtime or compile-time parsing and processing of SWF/SWC assets for use with OpenFL. SWF content can then be used for design or (beta) animation in projects deployed to desktop, web, mobile and console targets in both web and native technologies.

Use of this library for static design content has a track record in production. Use of this library for animation should be considered beta and may not be optimized for performance. Contributions to improve performance are welcome!

There are three primary code paths within the library:

  1. SWF

Type "swf" provides full parsing of the SWF/SWC format (based upon the original as3swf library by Claus Wahlers). This code is optimized primarily for completeness and accuracy rather than performance. Once a SWF has been fully parsed, it can be exported into a new runtime-optimized format (SWFLite, Animate) or there is a rudimentary implemention available for using the parsed SWF content directly at runtime. Those interested in improving this code path may be interested in looking at https://github.com/openfl/openfl-player as a start to testing and improving runtime SWF loading and playback.

  1. SWFLite

Type "swflite" is an older exporter format, previously integrated within OpenFL. The code exists in this library primarily for historical reasons. After parsing the SWF content using the "swf" code path, a new format was generated with the help of the Haxe serializer. Despite runtime file-size and performance improvements based on the format, the reliance on Haxe serialization had downsides to backward compatibility.

  1. Animate

Type "animate" is the latest exporter format, and the default for all targets. It combines the benefits of the "swflite" format while writing to JSON and compressing all assets into a single ZIP file. It can be iteratively improved while maintaining backward compatibility. The Macromedia SWF format also has these benefits, however it is optimized for a runtime different from modern web browsers. For example, images in a Macromedia SWF file may have premultiplied alpha applied to bitmaps already. There is no quick way to render this properly using HTML5 canvas. The Animate library format offers an opportunity for to pre-process SWF content into a flexible format optimized for modern production-use.

This library can be called automatically by the OpenFL/Lime command-line tools to process <library /> tags, or it can be used on the command-line to process SWF files into Animate ZIP files.

Usage

First, make sure that <haxelib name="swf" /> has been added to your project.

Then, you can add <library path="to/your.swf" preload="true" /> to include a SWF library. This will be available at runtime using the file name of the SWF (minus the ".swf") or you can add id="my-unique-id" to specify a custom name.

There is a (beta) option for generate="true" to generate Haxe classes for each "Export for ActionScript" type in the SWF file. The preload is also optional, but is recommended to simplify use.

You can create an "Export for ActionScript" clip from a SWF like this:

var clip = Assets.getMovieClip("my-swf:MyMovieClipName");

If you would prefer to create the whole timeline, use an empty clip name:

var timeline = Assets.getMovieClip("my-swf:");

If you use the 'generate' option, you would instead create a new instance like this:

var clip = new MyMovieClipName();

You can also process files from the command-line, and load them later:

haxelib run swf process
haxelib run swf process path/to/swfs
haxelib run swf process test.swf
haxelib run swf process test.swf path/to/test.zip
haxelib run swf process test.swf output/path

For example:

haxelib run swf process test.swf

This will generate a "test.zip" file which can be loaded at runtime later:

import swf.exporters.animate.AnimateLibrary;
import openfl.utils.Assets;

...

AnimateLibrary.loadFromFile("path/to/test.zip").onComplete(function(library)
{
    var clip = library.getMovieClip("MyMovieClipName");
    // or
    Assets.registerLibrary("my-swf", library);
    var clip = Assets.getMovieClip("my-swf:MyMovieClipName");
});

Installation

You can easily install SWF using haxelib:

haxelib install swf

To add it to a Lime or OpenFL project, add this to your project file:

<haxelib name="swf" />

Development Builds

Clone the SWF repository:

git clone https://github.com/openfl/swf

Tell haxelib where your development copy of SWF is installed:

haxelib dev swf swf

Rebuild the SWF library tools:

```bash
openfl rebuild tools
# or
cd swf
haxe rebuild.hxml
```

To return to release builds:

haxelib dev swf

swf's People

Contributors

andresa88 avatar barisyild avatar canigetapr avatar emibap avatar hasufel avatar horsetopus avatar jgranick avatar johnoneil avatar joshtynjala avatar kasparsj avatar mepsoid avatar mikkelmr avatar neni avatar pperidont avatar pythonmax avatar raggy avatar t1ml3arn avatar thinkry avatar vizanto avatar waffle-with-pears avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

swf's Issues

Swf doesn't render correctly in web/c++

I've created a minimal repro of a swf that looks different in openfl than flashplayer. you can download the fla/swf zip here
the image below shows the difference.
Screen Shot 2020-10-27 at 1 37 06 PMScreen Shot 2020-10-27 at 1 37 12 PM
The left is how it should look, the right is how it looks via openfl. ignore the yellow that is unrelated. I made this by drawing the number 4 with the paint brush tool, i copied the result to a new frame and applied Modify->Shape->straighten (might have been advanced straighten) and the straightened version seems to be showing incorrectly

Question

What version of ActionScript does this use?

HashLink Casting Error

Hey Josh, I'm not sure to what degree the SWF lib is expected to work with HashLink but I thought I should mention this. It seems to work okay in the neko, html5 and linux desktop targets.

The error appears in an otherwise blank openfl project when running openfl test hashlink
I have a single, fairly large swf pulled from an swc file, with lots of symbols exported for actionscript.
<library path="Assets/library.swf" preload="true" generate="true" />

The window appears, but with no contents painted, it's completely transparent, then after a few seconds the following is output to the console and the window closes.

Uncaught exception: Can't cast String to i32
Called from swf.exporters.animate.AnimateLibrary.~load.0(swf/exporters/animate/AnimateLibrary.hx:238)
Called from swf.exporters.animate.AnimateLibrary.~load.2(lime/app/Module.hx:0)
Called from lime.app.Future.onComplete(lime/app/Future.hx:128)
Called from swf.exporters.animate.AnimateLibrary.load(swf/exporters/animate/AnimateLibrary.hx:277)
Called from lime.utils.$Assets.~loadLibrary.0(lime/utils/Assets.hx:430)
Called from lime.utils.$Assets.~loadLibrary.1(lime/app/Module.hx:0)
Called from lime.app.Future.onComplete(lime/app/Future.hx:128)
Called from lime.utils.$Assets.loadLibrary(lime/utils/Assets.hx:412)
Called from lime.utils.Preloader.updateProgress(lime/utils/Preloader.hx:238)
Called from lime.utils.Preloader.load(lime/utils/Preloader.hx:181)
Called from $ApplicationMain.create(ApplicationMain.hx:128)
Called from $ApplicationMain.main(ApplicationMain.hx:25)
Called from fun$8236(?:1)

Versions

  • haxe: 4.1.3
  • openfl: 9.0.2
  • swf: 3.0.2
  • os: Xubuntu 20.04

README outdated

The development builds section is outdated at https://github.com/openfl/swf#development-builds

"
Go to the tools folder:

cd swf/tools

Tell haxe to build:

haxe build.hxml

"

The now correct actions would be

"
Go to the root directory of the cloned repository:

cd swf

Tell haxe to rebuild:

haxe rebuild.hxml

"

Note: I know this is something small but it is important to keep documentation up to date for people who are new to the libraries/frameworks and their tools

Incorrect capitalisation in package directory

I was getting this error while building an openfl project using assets from an swf.

Export/html5/haxe/_generated/MC_AchievementPopUp.hx:7: characters 73-115 : Type not found : skyPandaTiles_fla.MC_AchievementPopUp2_433

When I searched inside the _generated folder, there was a subdirectory called SkyPandaTiles_fla and inside of it, the file MC_AchievementPopUp2_433 existed.

It took me a moment to realise that the directory name began with an uppercase S, which is incorrect, as a package name in Haxe must begin with a lowercase letter. When I changed this manually and re-tested the error went away.

Error in AnimateLibraryExporter when compiled to Windows target

I thought I'd try compiling the swf lib to Windows for a slight speed up, I encountered this error:

Error: AnimateLibraryExporter.cpp
./src/swf/exporters/AnimateLibraryExporter.cpp(1582): error C2664: 'hx::ObjectPtr<lime::tools::Asset_obj> lime::tools::Asset_obj::__alloc(hx::Ctx *,String,String,lime::tools::AssetType,Dynamic,hx::Null<bool>)': cannot convert argument 4 from 'String' to 'lime::tools::AssetType'
./src/swf/exporters/AnimateLibraryExporter.cpp(1582): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called  
include\lime/tools/Asset.h(32): note: see declaration of 'lime::tools::Asset_obj::__alloc'

It's having trouble converting openfl.utils.AssetType to lime.tools.AssetType, which is confusing as the cast appears to be working on Neko and Hashlink targets.

Animations in SWF are glitchy

I'm attaching both a FLA and an accompanying SWF files (link) with a broken animation that used to be played correctly in OpenFL 8.9.6 but is not in OpenFL 9.0.2. There is a movieclip in the FLA file, which is exported to ActionScript as assets.Animation. In order to reproduce the bug, just import the movieclip and execute the following code:

addChild (new assets.Animation ());

Closer to the end of this animation, the animation pieces lump together in the upper left corner of the movieclip, which is wrong.

Runtime SwfLite scales matrices multiple times

Using the SwfLiteExporter causes graphical errors where child shapes appear in the wrong position. The problem is at SWFLiteExporter.hx#L141, L558 and L811 where the matrix is divided by 20. if the symbol is used multiple times it will be scaled again and again, we can avoid this with:

var matrix = placeTag.matrix.matrix;
matrix.tx = placeTag.matrix.translateX / 20;
matrix.ty = placeTag.matrix.translateY / 20;

@:bind class that extends another @:bind class - wrong result

I have a fla file with 2 assets linked to classes:
image

Box class:

@:bind class Box extends Sprite
{
    public var mc:MovieClip;

    public function new()
    {
        super();
    }
}

And Circle class:

@:bind class Circle extends Box
{
    public function new()
    {
        super();
    }
}

However when I instantiate Box and Circle - I see 2 boxes on the stage:

class Main extends Sprite
{
    public function new()
    {
        super();

        var box:Box = new Box();
        addChild(box);

        var circle:Circle = new Circle();
        circle.x = 200;
        addChild(circle);
    }
}

Result:
image

Is it a bug or known limitations that I should consider?

(Test project attached. Just run build.hxml)

inheritance_sample.zip

Best regards

generate="false" option is ignored

For some reason the generate option has no effect, the export for actionscript classes are always generated no matter what,

If it has been removed, we can update documentation (this repo readme, and openfl using swf assets tutorial).

Not enough arguments

What am I doing wrong??

public function playMovie(movieClip:String, sound:String, onComplete:Void->Void):Void
{
        barLeft = new Sprite();
        barRight = new Sprite();

        var audio:FlxSound = new FlxSound().loadEmbedded(sound);
        Assets.loadLibrary('$movieClip').onComplete(function(_) {
            clip = Assets.getMovieClip('$movieClip:');
            addChild(clip);

            addChild(barLeft);
            addChild(barRight);
            
            audio.onComplete = function() {
                onComplete();
                removeChild(clip);
                (cast (Lib.current.getChildAt(0), Main)).removeChild(this);
            };
            audio.play();
        });

        (cast (Lib.current.getChildAt(0), Main)).addChild(this);

        addEventListener(Event.ENTER_FRAME, onResize);
 }

Duplication Issue

There is a misduplication of movieclips problem with the swf library. A swf is attached that reproduces the problem.

In the example below, we can see that the object has been added extra.

You can drag the movieclips to see the duplicates.

image

Source code to reproduce: Swflite.zip

AVM1 SWF AssetLibraries have no AS Linkage names

SWF AssetLibrary bundles processed by openfl process command only have working AS Linkages if the source SWF file is of AVM2 (AS3) type. AVM1 SWF libraries don't have AS Linkages after being processed by openfl. The same thing happens when using swf-loader typescript package.

import * as libraryAS3 from "../../../assets/login-as3.swf";
import * as libraryAS2 from "../../../assets/login-as2.swf";
...
let library_as3 = await Utilities.GetLibraryAsync(libraryAS3);
let view_as3 = library_as3.getMovieClip("com.clubpenguin.login.views.NewPlayer"); //is a MovieClip
let library_as2 = await Utilities.GetLibraryAsync(libraryAS2);
let view_as2 = library_as2.getMovieClip("com.clubpenguin.login.views.NewPlayer"); //is null

Fix compile of haxelib script

The haxelib script (scripts/tools.hxml) relies on -lib openfl but it cannot resolve all of the internal source paths by design

For now, let's get a macro into OpenFL (using a define?) that allows us to bypass this restriction and get things up and running today

Relies on openfl/openfl#2390

Static Text instances result in warnings

sample fla + swf:
fonts.zip

The flash file above contains 3 text fields with 3 different fonts.

On processing the swf I see this:

src/swf/SWFTimelineContainer.hx:258: WARNING: excess bytes: 2, Tag: DefineFont3, Index: 3
src/swf/SWFTimelineContainer.hx:258: WARNING: excess bytes: 2, Tag: DefineFont3, Index: 7
src/swf/SWFTimelineContainer.hx:258: WARNING: excess bytes: 2, Tag: DefineFont3, Index: 11

If I add a dynamic text field with the same font family as one of the static text fields, then one of the warnings disappears.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.