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,
Mike


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: 7633_temp.jsx.zip

Good luck!

Expression for Source Text of text in Key comp:
thisComp.name.split("_")[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 (thisComp.name == 1) {a = "q1"}
if (thisComp.name == 2) {a = "w2"}
if (thisComp.name == 3) {a = "e3"}
if (thisComp.name == 4) {a = "r4"}
if (thisComp.name == 5) {a = "t5"}
if (thisComp.name == 6) {a = "y6"}
if (thisComp.name == 7) {a = "u7"}
if (thisComp.name == 8) {a = "i8"}
if (thisComp.name == 9) {a = "o9"}
if (thisComp.name == 10) {a = "p0"}
if (thisComp.name == 11) {a = "a@"}
if (thisComp.name == 12) {a = "s#"}
if (thisComp.name == 13) {a = "d&"}
if (thisComp.name == 14) {a = "f*"}
if (thisComp.name == 15) {a = "g-"}
if (thisComp.name == 16) {a = "h+"}
if (thisComp.name == 17) {a = "j="}
if (thisComp.name == 18) {a = "k("}
if (thisComp.name == 19) {a = "l)"}
if (thisComp.name == 20) {a = "z_"}
if (thisComp.name == 21) {a = "x$"}
if (thisComp.name == 22) {a = "c\""}
if (thisComp.name == 23) {a = "v'"}
if (thisComp.name == 24) {a = "b:"}
if (thisComp.name == 25) {a = "n;"}
if (thisComp.name == 26) {a = "m/"}


a[c];


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(thisComp.name,10) - 1;
if (isNaN(idx) || (idx > (lower.length-1)) || (idx < 0))
" "
else
(c == 0) ? lower[idx] : upper[idx];


Dan



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++){
try{
if (C.layer(i).source.name == thisComp.name){
str = C.layer(i).name;
break;
}
}catch (err){
}
}
str


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


Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]