Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting Question

  • Scripting Question

    Posted by Paul Benson
    on November 28, 2009 at 6:40 pm

    Trying to move up to scripting, and this is the closest forum I can find on the cow. I have seen something like this is a few scripts, and there is an example in the javascript tools guide for CS3. Essentially, the code is using a string as an array index. I’m not sure how this works. I’m thinking it is not a true array, so any insight is appreciated. Here is a code snippet which shows the values of all the properties of an object:

    var f = new File ("myfile");
    var props = f.reflect.properties;
    for (var i = 0; i < props.length; i++) { $.writeln('this property ' + props[i].name + ' is ' + f[props[i].name]); }

    How does the f[props[i].name] get decoded? props[i].name is a string. Is this some alternate method to access object properties? Like if props[i].name = "path", then this will output f.path? That's what it implies to be doing, but I haven't seen this specifically addressed.

    Thanks,
    Pauley

    Paul Benson
    replied 16 years, 8 months ago
    2 Members · 3 Replies
  • 3 Replies
  • Paul Benson

    November 28, 2009 at 7:02 pm

    Hmmm, well I’m still trying to wrap my head around it, but I did find this explanation.

    You can access ReflectionInfo objects in a Reflection object’s properties and methods arrays, by name or index:

    obj = new String ("hi");
    obj.reflect.methods[0];
    obj.reflect.methods["indexOf"];

    I assume this is not unique to ReflectionInfo objects. I’m still trying to visualize this. Seems like a nice shortcut to get the the parameters/properties you want.

    Pauley

  • Dan Ebberts

    November 28, 2009 at 8:19 pm

    In JavaScript, objects are also associative arrays, which can be accessed using strings. There’s a lot of info out there on JavaScript objects and associative arrays. Google is your friend. 🙂

    Dan

  • Paul Benson

    November 28, 2009 at 8:32 pm

    Thanks Dan. The problem with google is that my search results always gave back links to basic array methods and properties. Now I know how to properly phrase my search with “associative arrays”. Your post should help me narrow down my search.

    Thanks,
    Pauley

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