我一直在使用Swiffy来轻松输出.fla文件,但后来我发现,如果在iPad上以横向模式查看,显示屏会在项目的一半上交替“闪烁”白色。非常奇怪的行为,我无法在任何其他设备上复制。
所以,我已经开始尝试使用CreateJS来解决这个问题。我现在只知道足够的JS来编辑其他人开发的代码,所以到目前为止我的效率都很低。
我已经走到这一步了:
/* js
this.stop();
var t=setTimeout(function(){(this.play())}, 1000);
*/
or
/* js
this.stop();
setTimeout(this.play(), 1000);
*/
我无法让动画想到超时,我已经尝试了许多不同的变体来试图让一些魔法发生。它只是立即加载下一帧,它根本不会停顿。我在哪里错了?
这是原始的Actionscript:
stop();
var shortTimer:Timer=new Timer(1000);
shortTimer.addEventListener(TimerEvent.TIMER, timerN1);
shortTimer.start();
function timerN1(e:TimerEvent):void{
play();
shortTimer.reset();
}
任何帮助都会非常感激,因为我已经无法自行尝试解决这个问题,这是我几个星期的休息时间,而且我的客户变得越来越生气。更多的设计师,就编程而言仍然没有受过教育。同样,即使是一个建议在这一点上也会非常有用。似乎无法解决它。
答案 0 :(得分:3)
这种语法更正确:
/* js
this.stop();
var t=setTimeout(function(){(this.play())}, 1000);
*/
但是,您可能会发现“this”是Window,而不是调用它的MovieClip。你可以通过使用本地引用(在这种情况下,它的“_this”)来解决这个问题。
/* js
this.stop();
var _this = this;
var t=setTimeout(function(){
console.log(this, _this);
_this.play();
}, 1000);
*/
您可以通过查看控制台来测试这一点,看看“this”和“_this”之间的区别是什么。
干杯。
答案 1 :(得分:0)
您是否可以发布更多与您合作的代码?您是否尝试过使用onAnimationEnd函数:
var _this = this;
_this.onAnimationEnd = function() {
_this.stop();
setTimeout(function(){
_this.play();
}, 1000)
}
答案 2 :(得分:0)
尝试此操作以使您的范围在setTimeout
函数中保持活动状态:
sprite.on('animationend', function(event) {
event.target.stop();
setTimeout(animationend.bind(event.target), 1000);
});
function animationend() {
this.gotoAndPlay('run');
}
使用.bind()
,您可以传递一个对象作为被调用函数中的作用域。 More information here