How can I remove a background image or color from Flash-exported HTML and JS

时间:2015-10-06 08:56:31

标签: javascript html5 flash animation

I've done some animation using Adobe Flash CC, and then I exported it in HTML and JS, but I can't find the way to remove the background.

I see the function and all, but I don't know how to remove it.

Here is the html:

<html>
<head>
<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="Anime_V3.js"></script>

<script>
var canvas, stage, exportRoot;

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

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

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

function handleComplete(evt) {
    var queue = evt.target;
    ss["Anime_V3_atlas_"] = queue.getResult("Anime_V3_atlas_");
    exportRoot = new lib.Anime_V3();

    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">
    <canvas id="canvas" width="1340" height="605" style="background-color:#FFFFFF"></canvas>
</body>
</html>

And I'm sorry for this, but the JS is just to big to fit in here, so I put it on pastebin, here is the link:

http://pastebin.com/fvqpMChM

2 个答案:

答案 0 :(得分:0)

根据FLA的背景颜色,背景将作为内联样式添加到画布中。您可以删除该属性。

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

<canvas id="canvas" width="1340" height="605"></canvas>

请注意,如果您重新发布/导出内容,它将覆盖您的html,因此您可能希望在发布设置中将其关闭。

答案 1 :(得分:0)

我找到了一个可以让你用透明背景导出画布的工作。您可以在实际的Flash文件中将这一小段代码添加到第一帧:

document.getElementById("canvas").style.backgroundColor = "rgba(255,255,255,0)";

这样做的目的是在用户加载棋子时定位画布元素,然后将画布片的背景从舞台颜色改为完全透明的白色。这应该适用于所有支持画布的浏览器,并且每次导出时都不需要更改文件。