Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects slider evaluates to 0 when used with charAt() method

  • slider evaluates to 0 when used with charAt() method

    Posted by Caleb Payne on June 19, 2019 at 5:46 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.

    Kalleheikki Kannisto replied 7 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kalleheikki Kannisto

    June 19, 2019 at 6:15 pm

    You want to use Math.round(effect(‘Slider Control’)(‘Slider’).value) there. Note also .value at the end to retrieve the value of the slider rather than the slider as an object.

    Kalleheikki Kannisto
    Senior Graphic Designer

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy