Can you measure the width of a character in an AE expression? I have a type effect that requires a couple of layers, one with the type, and another moving behind the letters as they appear (simulating the little text bubbles you get when typing on an iPhone). It's very tedious animating the position of the bottom layer to match the text, so I'm wondering if it's possible to use any javascript tools to measure the characters and drive the position value.

Currently I have an expression driving the opacity like this, to automatically turn the background off for spaces:

theOffset=thisComp.layer(1).text.animator("Animator 1").selector("Range Selector 1").offset;
if (thisComp.layer(1).text.sourceText.substr(theOffset, 1) == " " ){0} else {100}


and another that folows the text animator range selector so that I can retime if I want without having to nudge keyframes till doomsday:

theOffset=thisComp.layer(1).text.animator("Animator 1").selector("Range Selector 1").offset;
try {
    transform.position.key(theOffset + 1).value
}
catch(error){[-10000,0]}//effectively hide it on errors (like the index going out of bounds)


…but this relies on me going through and creating keyframes to match the spacing of all the letters in the text, and frankly I'd rather be doing something else with the time that takes. so I'm trying to find a string method that I could use like this:

xOffset = thisComp.layer(1).text.sourceText.substr(1, theOffset).getTextWidth()


but getTextWidth obviously isn't a valid method. Is there a JS method that can get the size of a string on screen? There seems to be several solutions for this when the client is a web browser, but I can't find any that work for AE expressions.
So you want the width of the whole text object no single characters?
In that case you could use this: http://motionboutique.com/text-bounds-expresssion-580/
A tutorial plus sample project on how to get the bounding box of a text layer.

In case the link dies, here is the complete expression they use to determine the bounding box.

step = 1.0; // higher values speed things up (2 means two times faster) but reduce precision
L = thisComp.layer("MyTextLayer"); // text layer whose size must be evaluated

w = thisComp.width;
h = thisComp.height;
halfW = w / 2;
halfH = h / 2;
halfStep = step / 2;

left = w;
right = 0;
top = h;
bottom = 0;

// find left
found = false;
for (x = 0; !found &amp;&amp; x &lt; w; x+=step)
{
    if (L.sampleImage([x,halfH], [halfStep,halfH], true)[3] &gt; 0)
    {
        found = true;
        if (x &lt; left) 
            left = x;
    }
}
// find right
found = false;
for (x = w; !found &amp;&amp; x &gt;= 0; x-=step)
{
    if (L.sampleImage([x,halfH], [halfStep,halfH], true)[3] &gt; 0)
    {
        found = true;
        if (x &gt; right) 
            right = x;
    }
}
// find top
found = false;
for (y = 0; !found &amp;&amp; y &lt; h; y+=step)
{
    if (L.sampleImage([halfW,y], [halfW,halfStep], true)[3] &gt; 0)
    {
        found = true;
        if (y &lt; top) 
            top = y;
    }
}
// find bottom
found = false;
for (y = h; !found &amp;&amp; y &gt;= 0; y-=step)
{
    if (L.sampleImage([halfW,y], [halfW,halfStep], true)[3] &gt; 0)
    {
        found = true;
        if (y &gt; bottom) 
            bottom = y;
    }
}

/*"Size of text\n" + (right-left) + "x" + (bottom-top)*/
left + "," + top + "," + (right-left) + "," + (bottom-top)