Jacek Tomczak
Jacek Tomczak

Reputation: 1

Using AnmiateCC html5 output with Haxe

Because FLASH is Dead I have a mission to convert some games to work as html5. Graphics and animation is made on timeline in AnimateCC.

Until now the process looks like: publish to swc/swf, FlashDevelop -> AddToLibrary and I've access to all the objects. When publish target is HTML5 canvas I have two files:

testHaxe.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>testHaxe</title>

<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
<script src="testHaxe.js"></script>
<script>
var canvas, stage, exportRoot;
function init() {

    canvas = document.getElementById("canvas");
    images = images||{};

    var loader = new createjs.LoadQueue(false);
    loader.addEventListener("fileload", handleFileLoad);
    loader.addEventListener("complete", handleComplete);
    loader.loadManifest(lib.properties.manifest);
}

function handleFileLoad(evt) {
    if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
}

function handleComplete(evt) {
    exportRoot = new lib.testHaxe();

    stage = new createjs.Stage(canvas);
    stage.addChild(exportRoot);
    stage.update();

    createjs.Ticker.setFPS(lib.properties.fps);
    createjs.Ticker.addEventListener("tick", stage);
}

</script>

</head>
<body onload="init();" style="background-color:#D4D4D4;margin:0px;">
    <canvas id="canvas" width="550" height="400" style="background-color:#FFFFFF"></canvas>
</body>
</html>

testHaxe.js

(function (lib, img, cjs, ss) {

var p; // shortcut to reference prototypes
lib.webFontTxtFilters = {}; 

// library properties:
lib.properties = {
    width: 550,
    height: 400,
    fps: 24,
    color: "#FFFFFF",
    webfonts: {},
    manifest: [
        {src:"images/Bitmap1.png", id:"Bitmap1"}
    ]
};



lib.webfontAvailable = function(family) { 
    lib.properties.webfonts[family] = true;
    var txtFilters = lib.webFontTxtFilters && lib.webFontTxtFilters[family] || [];
    for(var f = 0; f < txtFilters.length; ++f) {
        txtFilters[f].updateCache();
    }
};
// symbols:



(lib.Bitmap1 = function() {
    this.initialize(img.Bitmap1);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,103,133);


(lib.в1 = function(mode,startPosition,loop) {
    this.initialize(mode,startPosition,loop,{});

    // Warstwa 1
    this.instance = new lib.Bitmap1();
    this.instance.setTransform(-2,-2);

    this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));

}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(-2,-2,103,133);


// stage content:
(lib.testHaxe = function(mode,startPosition,loop) {
    this.initialize(mode,startPosition,loop,{});

    // Layer 1
    this.instance = new lib.в1();
    this.instance.setTransform(85,90,1,1,0,0,0,49.5,64.5);

    this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));

}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(308.5,223.5,103,133);

})(lib = lib||{}, images = images||{}, createjs = createjs||{}, ss = ss||{});
var lib, images, createjs, ss;

I'm looking for a way to connect thouse files into haxe and access files on Stage or from library ex: new a1();

There are externs for createJS in haxeLib but I don't know how to use them with this output.

Upvotes: 0

Views: 200

Answers (1)

Philippe
Philippe

Reputation: 2631

You can write externs for your generated lib, eg.:

package lib;
import createjs.MovieClip;

@:native("lib.B1")
extern class B1 extends MovieClip {
}

@:native("lib.testHaxe")
extern class TextHaxe extends MovieClip {
    public var instance:B1;
}

Obviously that could be very tedious so I wrote a tool for it: https://github.com/elsassph/createjs-def

And posted a complete example here: http://philippe.elsass.me/2013/05/type-annotations-for-the-createjs-toolkit/

However it's currently broken for recent versions of Animate CC because the JS output has changed - it needs to be fixed.

Upvotes: 0

Related Questions