2 Flash canvas animations on the same HTML page

Asked

Viewed 110 times

1

I need to put 2 Flash animations on one page, appears only 1 animation, the other is blank.

I tried to make 2 "inits" but it didn’t work, When I went to export, I managed to libs with different names to avoid conflicts.

Someone’s been through something like this?

<script src="http://code.createjs.com/easeljs-0.8.1.min.js"></script>
<script src="http://code.createjs.com/tweenjs-0.6.1.min.js"></script>
<script src="http://code.createjs.com/movieclip-0.8.1.min.js"></script>
<script src="http://code.createjs.com/preloadjs-0.6.1.min.js"></script>
<script src="unitec58.js"></script>
<script src="skala20168.js"></script>
<script>

function init() {
    canvas = document.getElementById("canvas");
    images2 = images2||{};
    ss = ss||{};

    var loader = new createjs.LoadQueue(false);
    loader.addEventListener("fileload", handleFileLoad);
    loader.addEventListener("complete", handleComplete);
    loader.loadFile({src:"media/extra/unitec58_atlas_.json", type:"spritesheet", id:"unitec58_atlas_"}, true);
    loader.loadManifest(lib2.properties.manifest);
}

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

function handleComplete(evt) {
    var queue = evt.target;
    ss["unitec58_atlas_"] = queue.getResult("unitec58_atlas_");
    exportRoot = new lib2.unitec58();

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

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

function init2() {
    canvas = document.getElementById("canvas2");
    images1 = images1||{};
    ss = ss||{};

    var loader = new createjs.LoadQueue(false);
    loader.addEventListener("fileload", handleFileLoad2);
    loader.addEventListener("complete", handleComplete2);
loader.loadFile({src:"media/extra/skala20168_atlas_.json", type:"spritesheet", id:"skala20168_atlas_"}, true);
    loader.loadManifest(lib1.properties.manifest);
}

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

function handleComplete2(evt) {
    var queue = evt.target;
    ss["skala20168_atlas_"] = queue.getResult("skala20168_atlas_");
    exportRoot = new lib1.skala20168();

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

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

</script>
</head>

<body onload="init(); init2();" style="background-color:#D4D4D4">

<canvas id="canvas" width="300" height="250" style="background-color:#FFFFFF">
</canvas>

<canvas id="canvas2" width="300" height="250" style="background-color:#FFFFFF">
</canvas>
  • 1

    What do you mean Flash? It’s createjs, no?

  • The problem may be in stage = new .... This is a global variable, so there is only one Stage in your code. Try with var stage = . This will create a local variable in each function.

  • I tried that way too and it didn’t work. I’ve already changed the name of libs, still unsuccessful

  • You need to do the same with canvas, var canvas = ...

  • It really worked out

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.