【问题标题】:CreateJS play child movieClip timelineCreateJS 播放子电影剪辑时间线
【发布时间】:2015-03-03 06:16:29
【问题描述】:
我真的很想喜欢 CreateJS,但令人愤怒的是,AS3 中的基本功能无法正常工作或无法使用。这是一个简单的例子:
我在 MovieClip 中有一个简单的动画,一个从右到左移动的圆圈。我有一个
this.stop();
在第一帧,然后是一个
this.stop();
在最后一帧。
我将那个 mc 拖到主时间轴上,给它一个“main_mc”的实例,然后创建一个名为 init() 的函数
function init()
{
this.main_mc.play();
}
init();
这是我得到的错误:
未捕获的类型错误:无法读取未定义的属性“播放”
有什么想法吗?
【问题讨论】:
标签:
javascript
html
flash
canvas
createjs
【解决方案1】:
@thatkidrich 问题是“this”的范围是窗口,而您的“main_mc”不在窗口对象上。要引用您的实例,您必须通过“exportRoot”对象,该对象将为您提供当前在 FLA 舞台上的所有实例的引用。我也不建议在 FLA 中编写您的 JS,我只会使用导出的 JS 来构建资产。在您的情况下,我将通过 HTML 外部的代码控制“main_mc”。
例子:
function init() {
canvas = document.getElementById("canvas");
exportRoot = new lib.Balltimeline();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.update();
//This will give you a reference to your MC on stage.
var mc = exportRoot.main_mc;
mc.play();
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
}