0
votes

Sorry for my bad english,

Hello guys ^_^, I'm a newbie try to use createjs and Flash CC.

i'm creating an apps with the simple hitTest function in Flash CC (html5 Canvas), but looks like it seem not to work. There is two objects (a movieclip type object) on the canvas (and i put it on array called "arrTmbl"), when i try to mouseover on it, the console log always showing "Not Hit", here is my code:

var arrTmbl = ['tmbl0', 'tmbl1'];

var update = true;
stage.enableMouseOver(10);
stage.addEventListener("tick", f_tick);

function f_tick() {
if (update) {
    update = false;
    stage.update();
}
}

for (var i in arrTmbl) {
this[arrTmbl[i]].addEventListener("mouseover", function (e) {
    var pt = e.currentTarget.globalToLocal(stage.mouseX, stage.mouseY);
    if (e.currentTarget.hitTest(pt.x, pt.y)) {
        console.log("Hit");

    } else {
        console.log("Not Hit");
    }
});

this[arrTmbl[i]].addEventListener("pressmove", function (evt) {
    evt.currentTarget.x = evt.stageX;
    evt.currentTarget.y = evt.stageY;
    update = true;
});

this[arrTmbl[i]].addEventListener("pressup", function (jvt) {
    jvt.currentTarget.gotoAndPlay("hit");
});
}

Thanks for your helping,

1
This looks fine - the main thing would be to ensure that the reference this[arrTmbl[i]] is resolving properly. Here is a quick fiddle using an array of random squares instead. Requires EaselJS 0.8.0 due to the Graphics commands (color change) - jsfiddle.net/lannymcnie/1sL8o0gr - Lanny
Feel free to provide a link to your JavaScript lib file exported from Flash, and I can do a quick test. - Lanny
@Lanny, Thank you very much for your respon, i've use Adobe Flash CC build 14.1.0.96 and looks like it uses an EaselJS 0.7.1. And when i tried to put your code on flash cc, when i mouseover on the "square" it's not color change and in the console it shows "r.Fill is undifined". whether my easelJs need to upgrade, then how do i do it? - Arfian90
You can swap out the libraries with the latest in GitHub (version 0.8.0 isn't quite compliant). The sample I used will only work with EaselJS 0.8.0 and above, but that is just for the graphics color change -- the rest is fine. - Lanny
@Lanny, sorry for bothering you again, i've tried your code on the Flash CC and finally it works, but then i've figured it out, it looks like the hitTest won't work if the object is a movieclip. I don't know why, but if the object is created with the 'createjs.shape()' it will works fine. I've tried to put directly the movie clip on the stage and give it an instances name, or load it from library (with linkage) using 'new lib' and add it to stage, it won't work and always showing "Not hit" on the console. Is there a way, to use movieclip for hitTest? Thanks for your help Lanny. - Arfian90

1 Answers

0
votes

There is no reason to do a hitTest in this scenario. It is completely redundant with the mouseover listener. You can simplify your logic to just:

for (var i in arrTmbl) {
    this[arrTmbl[i]].addEventListener("mouseover", function (e) {
        console.log("Hit");
    });
}

The mouseover event only fires if a hit test has already returned true for the currentTarget.