Highlighted

Trying to create an array to target symbols for animation

Community Beginner ,
Feb 23, 2020

Copy link to clipboard

Copied

I have maps of districts named mc_1, mc_2, mc_3 etc...

I'm triggering an event when mouse hovers over them.
Instead of writing code for each mc_n I thought I could use arrays. But I have never done that before. Currently I have;

 

var district = [];
for (var i = 0; i <= 20; ++i) {district[i] = "mc_" + i;
}
stage.enableMouseOver(3); this.district[i].on('mouseover', function(){ this.district[i].gotoAndPlay(2); });
TOPICS
ActionScript, Code, How to, Timeline

Views

128

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Trying to create an array to target symbols for animation

Community Beginner ,
Feb 23, 2020

Copy link to clipboard

Copied

I have maps of districts named mc_1, mc_2, mc_3 etc...

I'm triggering an event when mouse hovers over them.
Instead of writing code for each mc_n I thought I could use arrays. But I have never done that before. Currently I have;

 

var district = [];
for (var i = 0; i <= 20; ++i) {district[i] = "mc_" + i;
}
stage.enableMouseOver(3); this.district[i].on('mouseover', function(){ this.district[i].gotoAndPlay(2); });
TOPICS
ActionScript, Code, How to, Timeline

Views

129

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 23, 2020 0
Adobe Community Professional ,
Feb 23, 2020

Copy link to clipboard

Copied

Hi.

 

You can assign the listeners to each instance without using an array. Like this:

stage.enableMouseOver(3);

for (var i = 0; i < 20; i++)
{
	this["mc" + i].on('mouseover', function(e)
	{
		e.currentTarget.gotoAndPlay(1);
	});
}

 

Please let us know if you have any further questions.

 

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 23, 2020 0