0
Beginner function help
Community Beginner
,
/t5/animate-discussions/beginner-function-help/td-p/11575718
Nov 07, 2020
Nov 07, 2020
Copy link to clipboard
Copied
What is wrong with this code? (HTML5 canvas) The first way works, but the second way doesn't.
var _this = this;
stage.enableMouseOver(3);
_this.icon_1.on('mouseover', function(){
_this.icon_1.gotoAndPlay('over');
_this.icon_1.cursor = "pointer";
});
_this.icon_1.on('mouseout', function(){
_this.icon_1.gotoAndPlay('out');
});
I need to do this for over 10 icons so I wanted to make it more module so I tried to convert it like this but it does nothing -
var _this = this;
stage.enableMouseOver(3);
_this.icon_1.addEventListener("mouseover", fl_MouseOverHandler);
function fl_MouseOverHandler()
{
gotoAndPlay('over');
cursor = "pointer";
}
_this.icon_1.addEventListener("mouseout", fl_MouseOutHandler);
function fl_MouseOutHandler()
{
gotoAndPlay('out');
}
TOPICS
Code
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
jonh15311545
AUTHOR
Community Beginner
,
LATEST
/t5/animate-discussions/beginner-function-help/m-p/11578304#M337289
Nov 08, 2020
Nov 08, 2020
Copy link to clipboard
Copied
This is my final code, works like a charm.
var frequency = 3;
stage.enableMouseOver(frequency);
var c = this;
var arrChildren = c.children;
for (var i = 0; i < arrChildren.length; i++) {
var mc_name = String(arrChildren[i].name);
var ourSubstring = "icon_";
if (mc_name.includes(ourSubstring)) {
this[mc_name].addEventListener("mouseover", overF.bind(this));
this[mc_name].addEventListener("mouseout", outF.bind(this));
this[mc_name].icon_text.text = String(arrChildren[i].name).replace('icon_', '');
}
}
function overF(e) {
e.currentTarget.gotoAndPlay("over");
this.cursor = "pointer";
}
function outF(e) {
e.currentTarget.gotoAndPlay("out");
this.cursor = "default";
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/animate-discussions/beginner-function-help/m-p/11578150#M337278
Nov 08, 2020
Nov 08, 2020
Copy link to clipboard
Copied
no matter what you add/change, your for-loop params have to match what exists.
for (var counter = startNum; counter <= endNum; counter++) {
this["icon_" + counter].addEventListener("mouseover", overF.bind(this));
this["icon_" + counter].addEventListener("mouseout", outF.bind(this));
this["icon_"+counter].icon_text.text = counter.toString();
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more


-
- 1
- 2