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.
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]);
}
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:
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).
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.
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.
Copy link to clipboard
Copied
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.