Activity › Forums › Adobe After Effects Expressions › Extendscript: info on Connect slider control to parameter??
-
Extendscript: info on Connect slider control to parameter??
Posted by Hamid Rohi-bilverdy on June 16, 2015 at 11:17 pmHi
I have searched through the scripting PDF, and i just can seem to find anything on how to connect a slider control to a parameter.
For instance I have created my main GUI, it contains a button, static text and a slider control.
Now I want this slider control to react to a layers paramter,say a opacity.
So when i slide the control on the GUI, then the opacity on the selected layer should correspond.
Can someone guide me towards a tutorial or similar so I have something to work on, I really dont know where to start.
I have created the slider button/control into my GUI, I can make buttons react with the “onClick” function, but how do I get the slider to react??
/HRB
Hamid Rohi-bilverdy replied 10 years, 10 months ago 2 Members · 9 Replies -
9 Replies
-
Dan Ebberts
June 16, 2015 at 11:28 pmYou need to set up onChange and/or onChanging functions to handle the changing slider values and attach them to the slider controls. I assume you’ve looked in the JavaScript Tools Guide–it’s described in there.
Dan
-
Hamid Rohi-bilverdy
June 17, 2015 at 9:37 amThank you Dan. I did actually not see this document.
Wow, that is a long PDF.I will try to mangle through the jungle and see what I can come up with.
Thanks again.
/HRB
-
Hamid Rohi-bilverdy
June 17, 2015 at 10:10 amSo far I only see infomation about the onChange on page 147, there are no exsamples or guide on how to use that word in a code…
-
Dan Ebberts
June 17, 2015 at 4:17 pmIt’s pretty straightforward:
function dragSlider(){
// do stuff
}myPal.myGrp.mySlider.onChanging = dragSlider;
Dan
-
Hamid Rohi-bilverdy
June 17, 2015 at 4:54 pmHi Dan
Thank you for taking your time to answer.
Yes, as you see in my script of my panel(Thanks to David Torno)
Here i have my slider button.
res = "group{orientation: 'row', alignment:['fill','fill'], alignChildren:['fill','fill'],\
groupOne: Group{orientation:'column' , alignment:['fill','fill'], alignChildren:['fill','fill'],\
myButton: Button {text: 'My Button'},\
myStaticTxt: StaticText {text: 'HAMID'},\
myCheck: Checkbox{text: 'CheckBox'},\
mySlider: Slider{text: 'Slider', value:30},\
myClose: Button {text: 'Close'},\Here you see i have assigned the group to myPanel and aslo my variable declaration of my button to the slider
//Assigning a group to myPanel add a res to it
myPanel.grp = myPanel.add(res);//How buttons are assigned to function
var mySliderBTN = myPanel.grp.groupOne.mySlider;
var pushBTN = myPanel.grp.groupOne.myButton;And here is what i have managed so far for actual pressing the button.
//THIS IS THE FUNCTION FOR THE SLIDER CONTROL
mySliderBTN.onChange = function() {alert("Slide me");
}
So I guess this output exactly the same as the short little function you described.
But my initial thougts was how do i actually link a parameter to the click of the button.
I want the slider to work as slider control for a selected layers opacity, going from 0 to 100.
The basics i know is to set the parameter for the opacity on a layer i could write:
var curItem = app.project.activeItem;
var selectedLayer = curItem.selectedLayers;
var curLayer = curItem.selectedLayers[0];var opaCity = curLayer.property("Transform").property("Opacity").setValue(50);
But to actualy have the slider button dynamicly from 0 to 100, here I am a bit lost…
/HRB
-
Dan Ebberts
June 17, 2015 at 5:02 pmI haven’t tested this, but I assume it would look like this:
mySliderBTN.onChange = function() {
var curItem = app.project.activeItem;
var selectedLayer = curItem.selectedLayers;
var curLayer = curItem.selectedLayers[0];
curLayer.property("Transform").property("Opacity").setValue(this.value);
}
With onChange, it’s probably not going to update the opacity until you let go of the slider. You might have better luck with onChanging, but I’m not sure.
Dan
-
Hamid Rohi-bilverdy
June 17, 2015 at 5:48 pmWow…. It did the trick, thank you very much.
If you would be so kind to explain to me, some curious questions which rised
1:
Can I use same technique for buttons such as progressbar, scroller?2:
What is the relationship between the button and this line “(this.value);”?3:
I am very happy with the result, so this question is more, is it possible.
I noticed, when sliding the controller, the comp window with the layer will reflect my button value AFTER i release the slider button. Is there a way to make it adaptiable, so the opacity value updates real time as i slide the button?Thank you very much for all your work for this community and also thanks for having a resourcefull site for beginners like me who have been magically chanted into this world of after effect scripting.
/Hamid
P.S All my post on the COW forum regarding extendscript, I have been posting in the after effect expression forum, is there another forum dedicated only for extendscript??
-
Dan Ebberts
June 17, 2015 at 6:12 pm1. I’m not sure what you mean, but any event callback function (onClick, onChange, etc.) should be able to update your comp in a similar way.
2. Inside the event callback function, “this” refers to the control that initiate the callback.
3. As I mentioned, you might try onChanging instead of onChange, but I don’t know if that will do it.
PS. The Cow doesn’t have an AE scripting forum. The Adobe user forums have one.
Dan
Reply to this Discussion! Login or Sign Up