FORUMS: list search recent posts

Comp Referencing itself

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mike Pindara
Comp Referencing itself
on Jun 18, 2014 at 2:21:18 am

I'm trying to build an animatable texting keyboard.

Each Key is a comp. it has all the attributes like the letter, number in the corner, and effects that happen when it is clicked.
Also there is a comp "Keyboard" that will hold all of the "Key" comps.

I've been trying to find out how to have each individual key look up into the keyboard comp and see what it's own layer name is. then use that to determine the source text that goes onto that individual key.

i know there is no way to change or look at the Composition name. and my last resort will be hard coding a ton of keys. Which if i need to make changes or think of effects to add, will be a huge pain.

please and thanks,

Return to posts index

Jelle Pothoven
Re: Comp Referencing itself
on Jun 18, 2014 at 2:38:12 pm

I'm afraid that's not possible.

What you can do is add an expression to the Source Text of the text in the Key comp that reads out the comp name. Then duplicate the Key comp and rename the comps to (for instance) "Key_a", "Key_b" and so on. I've written a short script for you that automates this task:

Good luck!

Expression for Source Text of text in Key comp:"_")[1];

Return to posts index

Mike Pindara
Re: Comp Referencing itself
on Jun 18, 2014 at 4:39:43 pm

I figured that was the case. I came up with a solution for myself also.

I created a "database" if you want to call it that. assigning a string to a number 1-26 (the number of keys required). I attached the code below so i dont have to explain the whole thing. the gist of it is, the original comp is named "1". i have all of the attributes attached there and linked as needed to a control later within "1". as i duplcate it in the project window, it updates the name 1-26. The code under the source reads the name of the comp and associates that to a string from which it gets the content of the key.

the downside is, since i wanted there to be a control layer within the "Keyboard" comp, ihave to individually link the attributes of each comp to the control layer manually. I did make it simpler by attaching all of the key attributes to one null layer within "Key" but then i still need to link all of those to the control layer in "Keyboard"

If you can think of a better system for that, that would be greatly appreciated. but right now i think its as dynamic as it can get

a = " ";
c = 0; //controls if it uses the first or second character//
//this allows me to use the same code to generate the number and letter//
//i just need to change this to 1 to generate the number instead//

if ( == 1) {a = "q1"}
if ( == 2) {a = "w2"}
if ( == 3) {a = "e3"}
if ( == 4) {a = "r4"}
if ( == 5) {a = "t5"}
if ( == 6) {a = "y6"}
if ( == 7) {a = "u7"}
if ( == 8) {a = "i8"}
if ( == 9) {a = "o9"}
if ( == 10) {a = "p0"}
if ( == 11) {a = "a@"}
if ( == 12) {a = "s#"}
if ( == 13) {a = "d&"}
if ( == 14) {a = "f*"}
if ( == 15) {a = "g-"}
if ( == 16) {a = "h+"}
if ( == 17) {a = "j="}
if ( == 18) {a = "k("}
if ( == 19) {a = "l)"}
if ( == 20) {a = "z_"}
if ( == 21) {a = "x$"}
if ( == 22) {a = "c\""}
if ( == 23) {a = "v'"}
if ( == 24) {a = "b:"}
if ( == 25) {a = "n;"}
if ( == 26) {a = "m/"}


Return to posts index

Dan Ebberts
Re: Comp Referencing itself
on Jun 18, 2014 at 6:19:23 pm

I think you could simplify that a little with something like this:

c = 0;
upper = '1234567890@#&*-+=()_$"' + "':;/";
lower = "qwertyuiopasdfghjklzxcvbnm"
idx = parseInt(,10) - 1;
if (isNaN(idx) || (idx > (lower.length-1)) || (idx < 0))
" "
(c == 0) ? lower[idx] : upper[idx];


Return to posts index

Dan Ebberts
Re: Comp Referencing itself
on Jun 18, 2014 at 4:08:15 pm

The best idea I can come up with would be to loop through all the layers of the Keyboard comp, looking for the one that has a source comp with a name that matches the Key comp. I did a little test with this source text expression in a Key comp and it seems to work:

C = comp("Keyboard");
str = "not found";
for (i = 1; i <= C.numLayers; i++){
if (C.layer(i) =={
str = C.layer(i).name;
}catch (err){

The try/catch is there because not all layers have sources.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved