• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Setting a tool property using JavaScript API

Community Beginner ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Hi everyone,

 

I would like, in reaction to certains events, to select a tool and change its properties. Events are working fine.

 

Selecting a tool is done this way (example with the Brusgh tool):

fl.selectTool('brush');

 

We are are supposed to be able to get the current this way following the documentation, but it does not work.

var theTool = fl.tools.activeTool;

I can't catch any error with a try/catch, but any line of code after this one will not execute.
Even if it would work, it would be a read only access to the tool, as stated in the documentation. 

 

So, how to change a tool property (the Brush tool size for example) using the JavaScript API?

Would the solution be to create a custom tool based on an existing one, and set this custom tool properties during it's creation?

In a context where a property needs to be changed, would it mean creating a new custom tool each time this property changes?

 

Or am I thinking the wrong and is there a better solution?

 

Many thanks.

TOPICS
Ad development , Code

Views

334

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
community guidelines
Community Expert ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

you probably have an error after that line.  try:

 

var theTool = fl.tools.activeTool;

for(var s in theTool){
fl.trace(s+" : "+theTool[s]);
}

Votes

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
community guidelines
Community Beginner ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Hi kglad, thank you for your answer. 

 

Unfortunately, that does not work either. I created a minimal command script using only the snippet you linked (wondering that maybe something else in my original script could interfere in any way with it), and I am receiving this error when executing it:

animate_js_error.png

 

Here is the minimal command script:

if(fl.getDocumentDOM() != null)
{
    var theTool = fl.tools.activeTool;
    for(var s in theTool){
        fl.trace(s + " : " + theTool[s]);
    }
}

 

I am using the up to date version of Animate (v 21.0.4).

Votes

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
community guidelines
Community Expert ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

i see this after selecting the 2nd tool on my toolbar and running that script:

 

sampleProperty : foo
position : 2
depth : 2
iconID : 0

 

and no error.

 

save that jsfl with name customBrush_v000.jsfl, open a fla and click command>run and navigate to customBrush_v000.jsfl.

Votes

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
community guidelines
Community Beginner ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Thank you, it works this way on my side too. 

 

I'm back investigating further on how to change a tool property. 

Votes

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
community guidelines
Community Expert ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

LATEST

you probably had a duplicate customBrush.jsfl somewhere with an (unrelated to my posted code) error in it and you were testing the one with the error instead of the one you thought you were testing.

Votes

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
community guidelines