-
1. Re: Super easy checkbox script, but not work!!!!
David Torno Jan 6, 2014 3:53 PM (in response to zipkiev)For a variable to be used inside a function, it would need to be declared within the function or passed into it.
function test1(myCheckbox){
myProperty = app.project.activeItem.selectedLayers[0].property("position");
convertToKeyframes(myProperty);
function convertToKeyframes(myCheckbox, theProperty){
if(myCheckbox.value==true){
do my stuff;
}
}
}
-
2. Re: Super easy checkbox script, but not work!!!!
zipkiev Jan 7, 2014 4:32 AM (in response to David Torno)thx for reply but, i try and it not work... i think i can't transfer data from this
var checkbox1= some_panel.add("checkbox", undefined, "checkbox1");
checkbox1.value=true;
to this
function test1(myCheckbox)
{
}
i try do something like this
var Button4= some_panel.add("button", undefined, "ExpToKey");
Button4.onClick=test1(checkbox1); and not work.
PS can i use global names, other?, i try(public) but AE script give me error, for now it is to many work to add just a checkbox....
-
3. Re: Super easy checkbox script, but not work!!!!
cswaim080880 Jan 7, 2014 3:16 PM (in response to zipkiev)Hi zipkiev,
Technically speaking, since checkbox1 is declared at the global scope, the function test1 will have access to it. You shouldn't need to pass it to test1. The only way it wouldn't work is if you tried to access a variable defined within a function at the global scope level...but even that can work in ways that are unexpected. Javascript can be a little funky about scope and in general you may find that even though your accessing an object that is out of "scope" for that function...it could still work as expected. Javascript is a very forgiving language which can make finding the route cause of a problem hard. In addition, the way you attempted to pass it to the onClick eventHandler will not work. That is looking for a Function instance...not a function call. The only thing passed to the event handler is the Event object which is passed to it at the system level (unable to override).
Would you feel comfortable sharing your full code so we might help debug it?
I created a script to test out exactly what you did...here's what mine was
var some_panel = new Window("palette", "Test", undefined, {resizeable: true});
var checkbox1= some_panel.add("checkbox", undefined, "checkbox1");
checkbox1.value=true;
function test1() {
myProperty = app.project.activeItem.selectedLayers[0].property("position");
convertToKeyframes(myProperty);
}
function convertToKeyframes(theProperty) {
if(checkbox1.value==true) {
alert("it's true");
}
}
var button = some_panel.add("button", undefined, "Test");
button.onClick = test1;
some_panel.show();
When I run this, I get the checked value properly when it gets to "checkbox1.value == true" so there could be some other issue with your script. One thing I noticed about the code you posted was that you did not close the Function definition for function test1 with a closing curly brace. That would account for the code not running at all (but not a runtime issue).
If you can post your entire script, I could give better feedback...but hopefully this helped!
Calvin -
4. Re: Super easy checkbox script, but not work!!!!
zipkiev Jan 8, 2014 10:22 AM (in response to cswaim080880)thx guys for reply , i find a problem.. the problem is that I declare a variable in a function where i create a window(pallet with buttons), and other variables(from other functions) cant see this checkbox inside this function... everything was decided very simply by shifting the variables where i later put checkbox in top of script(above other function) so now everyone could see checkbox.
Sorry for bad English

