我如何将swf文件导入画布

时间:2015-02-26 14:13:11

标签: javascript object canvas preload createjs

我想将swf文件导入我的画布 这是我的鳕鱼

我的功能是我预装了我的swf

var canvas, stage, exportRoot, images;


function init() {

    canvas = document.getElementById("canvas");

    images = images||{};

    var manifest = [
        {src:"/...octo12.swf"},

    ];


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


    loader.onProgress = handleProgress;
    stage = new createjs.Stage(canvas);
    createjs.Ticker.setFPS(22);
    createjs.Ticker.addEventListener("tick", stage);

    var image = new createjs.Bitmap("/../logo.png");
    image.x = 300;
    image.y = 150;

    stage.addChild(image);

    var progress = new createjs.Shape();

    var progressBellow = new createjs.Shape();
    progress.graphics.beginStroke("#FF00FF").drawRect(450,440,500,30);
    progressBellow.graphics.beginStroke("#FF00FF").drawRect(450,440,500,30);
    // progress.graphics.setStrokeStyle(8,"round").beginStroke("#FFF");


    function handleProgress(event) {
        progress.graphics.clear();
        // Draw the progress bar
        progress.graphics.beginFill("#FF00FF").drawRect(450,440,500*(event.loaded / event.total),30);

    }

    stage.addChild(progress,progressBellow);
    stage.update();
}


function handleComplete() {
//================================stage==========================================================

    stage = new createjs.Stage(canvas);

//================================child==========================================================

    stage.addChild(exportRoot);
    stage.update();
    stage.enableMouseOver();

//================================ticker=========================================================

    createjs.Ticker.setFPS(30);
    createjs.Ticker.addEventListener("tick", stage);

。 我有home.html我尝试导入它们

<canvas id="canvas"  width="1300" height="800" style="max-height: 100%;height: 25%;width: 20%;margin-left:40%;margin-top: 15%">
    <object width="400" height="50" data="/..../swf/octo12.swf"></object>
</canvas>

导入不起作用,如何将它们导入canvas元素 THX。

1 个答案:

答案 0 :(得分:0)

您应该使用createjs.DomElement。将您的对象移出canvas元素并为其指定id。

   <canvas id="canvas"  width="1300" height="800"></canvas>
   <object id="myswf" width="400" height="50" data="/..../swf/octo12.swf"></object>

然后你可以使用domElement来包装它并将它添加到你的舞台上(假设你正在使用jQuery):

var domElement = new createjs.DOMElement($("#myswf"));
stage.addChild(domElement);