how to target a MovieClip with createjs

前端 未结 1 1461
梦谈多话
梦谈多话 2021-01-28 06:13

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 yo

1条回答
  •  清歌不尽
    2021-01-28 06:43

    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
    }
    

    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);
    

    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));
    

    Hope that helps!

    0 讨论(0)
提交回复
热议问题