前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【easeljs】事件汇总

【easeljs】事件汇总

作者头像
黒之染
发布2018-10-19 14:32:09
9280
发布2018-10-19 14:32:09
举报
文章被收录于专栏:黒之染开发日记

文章说明:为了方便我自己查找easeljs的所有事件,所以我从easeljs的文档里抄过来加上自己的翻译,会慢慢补全,漏了的,错了的,评论一下我会补上去哦。(不确定翻译对不对的地方我会留着原文。)

  1. 继承自,表示所有继承自那个对象的对象都有这个事件。
  2. 定义于,表示只有这个对象才有这个事件。
  3. 加入版本,表示从这个版本起才加入这个事件,老版本没有这个事件。
  4. “此对象”表示被添加了这个事件的对象
  5. 与jquery和js一致,事件的回调函数第一个参数会带上事件对象,在easeljs文档event类中可以看到各个事件属性的说明。
  6. stage的事件全加进来了

easeljs事件默认是不支持touch设备的,需要这样才可以 var stage = new createjs.Stage("canvasId"); createjs.Touch.enable(stage);

添加事件的方法

on ( type listener [scope] [once=false] [data] [useCapture=false] ) Function

继承自 EventDispatcher A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener. This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The wrapper function is returned for use with removeEventListener (or off). IMPORTANT: To remove a listener added with on, you must pass in the returned wrapper function as the listener, or use remove. Likewise, each time you call on a NEW wrapper function is subscribed, so multiple calls to on with the same params will create multiple listeners. Example

代码语言:javascript
复制
var listener = myBtn.on("click", handleClick, null, false, {count:3});
function handleClick(evt, data) {
    data.count -= 1;
    console.log(this == myBtn); // true - scope defaults to the dispatcher
    if (data.count == 0) {
        alert("clicked 3 times!");
        myBtn.off("click", listener);
        // alternately: evt.remove();
    }
}

Parameters:

type String The string type of the event. listener Function | Object An object with a handleEvent method, or a function that will be called when the event is dispatched. [scope] Object optional The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent). [once=false] Boolean optional If true, the listener will remove itself after the first time it is triggered. [data] optional Arbitrary data that will be included as the second parameter when the listener is called. [useCapture=false] Boolean optional For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase. Returns:

Function: Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.

added

继承自 DisplayObject 当此对象被add到其它容器对象时触发

click

继承自 DisplayObject 加入版本 0.6.0 在用户按下左键并在此对象上松开左键后触发。

dblclick

继承自 DisplayObject 加入版本 0.6.0 当用户在此对象上双击左键后触发。

drawend

定义于 stage 加入版本 0.7.0 每次显示列表被绘制到canvas后并且restore过canvas context后触发。 Dispatched each update immediately after the display list is drawn to the canvas and the canvas context is restored.

drawstart

定义于 stage 加入版本 0.7.0 在清除画布和绘制显示列表之前触发。可以在调用event对象上使用preventDefault取消这次绘制。 Dispatched each update immediately before the canvas is cleared and the display list is drawn to it. You can call preventDefault on the event object to cancel the draw.

mousedown

继承自 DisplayObject 加入版本 0.6.0 用户在此对象上按下左键后触发。

mouseenter

定义于 stage 加入版本 0.7.0 当鼠标指针从canvas区域外(mouseInBounds == true)移进canvas区域(mouseInBounds == false)后触发。这是目前唯一非点击的鼠标输入事件。

mouseleave

定义于 stage 加入版本 0.7.0 当鼠标从canvas区域内(mouseInBounds == true)移出(mouseInBounds == false)后触发。这是目前唯一非点击的鼠标输入事件。(我也不知道为何这里的mouseInBounds和上面的相反,看原文吧)

mouseout

继承自 DisplayObject 加入版本 0.6.0 当用户鼠标从该对象的任意一个子项离开后触发。这个事件一定要启用enableMouseOver。另请参阅rollout。(写好rollout后如果我还记得这里,会把这个链接弄好)

mouseover

继承自 DisplayObject 加入版本 0.6.0 当用户鼠标进入该对象的任意一个子项后触发。这个事件一定要启用enableMouseOver。另请参阅rollout。(写好rollout后如果我还记得这里,会把这个链接弄好)

pressmove

继承自 DisplayObject 加入版本 0.7.0 在此对象上发生了mousedown事件后,无论鼠标是否移动,pressmove事件都会持续发生在此对象上,直到松开鼠标按钮。这事件在拖拽和类似的需求里很有用。 (如果stage上加了这个事件侦听,当stage上什么元素都没有时,这个是无效的,需要用stagemousemove

pressup

继承自 DisplayObject 加入版本 0.7.0 在此对象上发生了mousedown事件后,松开鼠标会触发。这事件在拖拽和类似的需求里很有用。

removed

继承自 DisplayObject 当此对象从它的父对象上移除后会触发。

rollout

继承自 DisplayObject 加入版本 0.7.0 这个事件和mouseout很像,但有这些不同:它不冒泡,而且它把该对象的内容认为是一个整体。 例如,myContainer包含着两个有重叠部分的子项:shapeAshapeB。用户移动他的鼠标到shapeA上,然后直接移到shapeB上,然后离开他们俩。如果myContainerMouseout:event,会收到两个事件,每个事件指向一个子元素:

  • 当鼠标离开shapeAtarget=shapeA
  • 当鼠标离开shapeBtarget=shapeB

然而当事件换成rollout,只会在离开myContainer时才会触发事件(不仅仅是离开shapeB),target=myContainer。这个事件一定要启用enableMouseOver。 (jquery也有这样的,但是我忘记jquery中哪个是只离开父对象才触发了。)

rollover

继承自 DisplayObject 加入版本 0.7.0 这个事件和mouseover很像,不同之处跟rolloutmouseout的不同之处是一样的。这个事件一定要启用enableMouseOver

stagemousedown

定义于 stage 加入版本 0.6.0 用户在canvas上按下左键后触发。

stagemousemove

定义于 stage 加入版本 0.6.0 当用户在canvas上移动鼠标时持续触发。

stagemouseup

定义于 stage 加入版本 0.6.0 当用户在stage的某处按下左键,然后在页面中能接收事件的任意一处(不同浏览器有些不同)松开左键。可以使用mouseInBounds检查鼠标是否在stage范围内。

tick

继承自 DisplayObject: tick:642 加入版本 0.6.0 Dispatched on each display object on a stage whenever the stage updates. This occurs immediately before the rendering (draw) pass. When update is called, first all display objects on the stage dispatch the tick event, then all of the display objects are drawn to stage. Children will have their Tick:event event dispatched in order of their depth prior to the event being dispatched on their parent. Event Payload:

  • target Object The object that dispatched the event.
  • type String The event type.
  • params Array An array containing any arguments that were passed to the Stage.update() method. For example if you called stage.update("hello"), then the params would be ["hello"].
  • paused Boolean 指出ticker当前是否暂停
  • delta Number 从上次触发事件以来,经过了多少毫秒。
  • time Number Ticker实例化之后经过了多少毫秒
  • runTime Number Ticker实例化之后未被暂停的状态下经过了多少毫秒。例如,你可以决定用time-runTime初始化后被暂停的总时间(The total time in ms that Ticker was not paused since it was initialized. For example, you could determine the amount of time that the Ticker has been paused since initialization with time-runTime.)

tickend

Defined in tickend:294 Available since 0.7.0 Dispatched each update immediately after the tick event is propagated through the display list. Does not fire if tickOnUpdate is false. Precedes the "drawstart" event.

tickstart

Defined in tickstart:287 Available since 0.7.0 Dispatched each update immediately before the tick event is propagated through the display list. You can call preventDefault on the event object to cancel propagating the tick event.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 添加事件的方法
    • on ( type listener [scope] [once=false] [data] [useCapture=false] ) Function
    • added
    • click
    • dblclick
    • drawend
    • drawstart
    • mousedown
    • mouseenter
    • mouseleave
    • mouseout
    • mouseover
    • pressmove
    • pressup
    • removed
    • rollout
    • rollover
    • stagemousedown
    • stagemousemove
    • stagemouseup
    • tick
    • tickend
    • tickstart
    相关产品与服务
    容器服务
    腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档