如何使用createjs定位MovieClip [英] how to target a MovieClip with createjs

查看:999
本文介绍了如何使用createjs定位MovieClip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图导出组合照片动画在flash中正常工作但在html5画布中导出时没有。

Im trying to export an group photo animation that works fine in flash but not when exported in html5 canvas.

诀窍是简单:每张照片都是按钮,当你将鼠标滚动到某人的照片上时,他的作业标题会出现。

The trick is "simple" : each photo is a button and when you roll your mouse over the picture of someone, his jobtitle appears.

我无法通过createjs实现这一目标!

Ican't make it happen with createjs !

我的舞台上有一个名为jobs_cont的MovieClip实例,其时间轴有不同的关键帧和每个人的工作标签。

I have a MovieClip instance on my stage named "jobs_cont" whose timeline has different keyframes and labels for everyone's jobtitles.

事情就是我没有成功定位jobs_cont并在按钮悬停时在其时间轴中使用gotoAndPlay特定的框架或标签。

The thing is i'm not successfull with targeting "jobs_cont" and using gotoAndPlay a specific frame or label in its timeline when a button is hovered.

单独识别警报指令但不识别jobs_cont.gotoAndPlay:

the "alert instruction" alone is recognised but not the "jobs_cont.gotoAndPlay":

var frequency = 3;
stage.enableMouseOver(frequency);
this.mybutton.addEventListener("mouseover", fl_MouseOverHandler);
function fl_MouseOverHandler(){ 
    this.jobs_cont.gotoAndPlay("mylabel");
    alert("hovered by mouse");
    // end of your personalized code
}

我想我一定要错过在createjs中以jobs_cont为目标的东西,但我是javascript中的新手,尽管我进行了一天的研究,却无法弄明白。
如果有人可以给出提示。
谢谢。

I think i must miss something targeting "jobs_cont" in createjs but i'm newbie in javascript and can't figure it out despite my day of researches. If someone could give a hint. Thank you.

推荐答案

您正在处理范围问题。如果使用上面的语法在时间轴上定义函数,则函数没有范围,因此变为 Window

You are dealing with scope issues. If you define a function on your timeline using the above syntax, the function doesn't have a scope, so this becomes Window.

您可以更改要在当前对象上定义的函数语法:

You can change the function syntax to be defined on the current object:

this.fl_MouseOverHandler = function(){ 
    this.jobs_cont.gotoAndPlay("mylabel");
    alert("hovered by mouse");
    // end of your personalized code
}

最后,JavaScript没有' t自动为事件监听器提供函数范围(还是!),因此您必须自己调整函数的范围。如果你有一个0.7.0或更高版本的EaselJS,你可以使用上的而不是 addEventListener (< a href =http://www.createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on\"rel =nofollow> docs )。请注意,您还必须使用 this.fl_MouseOverHandler

Lastly, JavaScript doesn't automatically provide function scope for event listeners (yet!) so you have to scope the function yourself. If you have a version 0.7.0 or later of EaselJS, you can use the on method instead of addEventListener (docs). Note that you have to use this.fl_MouseOverHandler as well.

this.mybutton.on("mouseover", this.fl_MouseOverHandler, this);

您还可以使用实用工具方法调整函数范围,例如 Function.prototype .bind() docs ):

You can also scope the function using a utility method such as Function.prototype.bind() (docs):

this.mybutton.addEventListener("mouseover", this.fl_MouseOverHandler.bind(this));

希望有所帮助!

这篇关于如何使用createjs定位MovieClip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆