ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

slider evaluates to 0 when used with charAt() method

COW Forums : Adobe After Effects

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


Caleb Payne
slider evaluates to 0 when used with charAt() method
on Jun 19, 2019 at 5:46:57 pm

Hello! this post is more about my understanding of the language than it is a problem to solve.

I'm using the charAt() method on a text layer's sourceText property, and attempting to pass sliderValue as its first and only argument, where sliderValue points to a slider effect on the same layer, like this:



//expression applied to a text layer's sourceText property

sliderValue = effect('Slider Control')('Slider');
myString = 'quickbrownfox';
newText = myString.charAt(sliderValue);
newText;



I would expect this to return a single letter from the "quickbrownfox" string, corresponding to the index provided by the slider, as long as it's within range. For example, if my slider is set to 4, the text should be "k."

However, the above always returns "q" suggesting that sliderValue is evaluating to 0 when passed into charAt().

One strange thing is that is that adding or subtracting 0 or (even an empty string) to sliderValue makes it work as expected. Alternatively, using one dimension of a point control in place of a slider works too. While writing this I've also found that wrapping sliderValue in a parseInt() or Math.floor() method is another work-around.

It appears as if charAt() can't make sense of a slider value unless it's deliberately typed as an integer.

Does that sound right? I've never run into this before so I'm just wondering if anyone has had similar experiences or has further insight.


Posts IndexRead Thread 


Current Message Thread:





© 2019 CreativeCOW.net All Rights Reserved
[TOP]