Skip to main content
eriks67544684
Participant
September 12, 2018
Answered

Change color tint/fill of a symbol in an Animate Canvas document?

  • September 12, 2018
  • 2 replies
  • 10332 views

Hi, how do I change the color tint of a symbol/shape in a HTML5 Canvas document (with code)? *

Alternatively how do I change the fill-color inside a symbol/shape (with code)? **

My case is that I have to import a svg/ai-file into a movie-clip and that svg/ai-file consists of 20-100 elements. I've made each element mid-grey, so it's possible to tint them easily. I manually have to create a button of each element (since they have to be clickable) and I also have to give each one a unique instance name. That procedure is far from ideal but it still goes pretty quick. For the record, yes I have to get the elements from an svg/ai-file and they are all different in terms of shape and placing. I will also have to repeat this process every time I get a new project (new project means a new svg/ai-file).

I'm going to put the instance names of these 20-100 elements in an array and read in data from a csv/xls-file. Depending on which value each element is given from the csv/xls-file I want them to be filled/tinted with 1 of 3 specific colors.***

* I've read that color tinting is demanding in terms of performance and somewhat limited in usage.

** I've found guides on how to generate a shape and set the fill color of that shape, but haven't figured out how to apply it on a shape that's already created.

*** Sure, I can make 3 different keyframes for each element with different colors and correspond the frame number with the data in the csv/xls-file, but if I manually have to do that for 20-100 elements, on each project, that's not a viable option.

I'm not looking for a solution to my entire case, I just want to be able to switch the tint/fill of my symbols/shapes! It shouldn't be rocket science, right?

I've searched and searched but had no luck. Sorry if my English is bad. Thanks for any support!

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

You can use the shape property for the stroke and the shape_1 for the fill. Like this:

this.button.shape.graphics._stroke.style = "rgb(128,22,35)"; // 'button' is the instance name

this.button.shape_1.graphics._fill.style = "rgb(20,22,36)";

I hope this helps.

Regards,

JC

2 replies

Participating Frequently
March 24, 2020

Hi

I had the same problem and tried this but didn't work.

I have a button named "StroboON" formed of a dynamic text named "ONOFF" and a rectangle named "BG", so I wrote in the code:

this.StroboON.BG.shape_1.graphics._fill.style = "rgb(20,22,36)";

but it didn't work

Thank you in advance

 

JoãoCésar17023019
Community Expert
Community Expert
March 24, 2020

Hi.

By default, Animate CC exports everything as texture. For being able to change a color of a shape created in the IDE at runtime you must do one of the following steps:

 

- Selectively set a single symbol instance to not be exported as a texture. For this, you must go to File > Publish Settings... > JavaScript/HTML > Image Settings > Symbols > Change... and uncheck the symbol you want to change the fill color via code;

 

- Or export everything as vectors by going to File > Publish Settings... > JavaScript/HTML > Image Settings, and in the Export as dropdown menu choose Image Assets and then uncheck Export Image assets. Even unchecking Export Image assets is necessary to choose Image Assets in the dropdown menu first due to a bug.

 

I hope this helps.

 

 

Regards,

JC

Known Participant
May 28, 2021

Hi.

 

Very interesting points.

 

Thank you very much for your contribution, @roguestreak!


thank you so much 

it is work

you helps me with all of my questions.

 

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
September 12, 2018

Hi.

You can use the shape property for the stroke and the shape_1 for the fill. Like this:

this.button.shape.graphics._stroke.style = "rgb(128,22,35)"; // 'button' is the instance name

this.button.shape_1.graphics._fill.style = "rgb(20,22,36)";

I hope this helps.

Regards,

JC

eriks67544684
Participant
September 12, 2018

Wonderful, thank you for your quick reply!! That helped a lot!

JoãoCésar17023019
Community Expert
Community Expert
September 12, 2018

Excellent! You're welcome!