Copy link to clipboard
Copied
Is it possible to work with "true" Object Orientation in ExtendScript? I've tried to create classes and Objects with JS Synthax, but that won't work:
class Person {
constructor(name, surname) {
this.name = name;
this.surname = surname;
}
}
var person = new Person('Jack', 'Smith');
alert(person);
This only returns "invalid use of reserved word class".
What I am actually trying to do in the long run is to build an UI based on Objects. So, speaking in Pseudocode:
Class myUI {
constructor(group , dropdown1, text1 )
this.group = group (parameter)
this.dropdown1 = group.add(dropdownlist (parameter))
this.text1 = group.add(edittext (parameter))
}
...etc
myUI(group,dropdown,text);
Any Idea how something like this could work?
ExtendScript is based on super old ECMA version 3.something. So to imitate a Class, you'd need to use the old way, like this:
function Person(name, surname){
this.name = name;
this.surname = surname;
}
var person = new Person('Jack', 'Smith');
alert(person);
Copy link to clipboard
Copied
ExtendScript is based on super old ECMA version 3.something. So to imitate a Class, you'd need to use the old way, like this:
function Person(name, surname){
this.name = name;
this.surname = surname;
}
var person = new Person('Jack', 'Smith');
alert(person);
Copy link to clipboard
Copied
Thanks Tomas, that seems to work great!
First test running fine:
var myPanel = new Window("palette","title",undefined);
var dropContent = ["Slideshow","Texttafel","Typo Big","Video Container"];
function myUI(group, dropdownlist,myFirstText){
this.group = group;
this.dropdownlist = dropdownlist;
this.myFirstText = myFirstText;
}
var newRow = new myUI('group', 'dropdownlist,undefined,dropContent','edittext {text:\'bla\'}');
myPanel.add(newRow.myFirstText);
myPanel.center();
myPanel.show();
Copy link to clipboard
Copied
Hello, is there any chance you could send me some sort of post about classes in after effects? I heard from a coder that they are useful but I just don't really know what they are. Google seems to think I am looking for extendscript courses when I type"class" so it's hard to find anything about it. I wanna learn! xD thanks!
Copy link to clipboard
Copied
Classes are the backbone of any object oriented language - wich extendScript is sadly only partly. As Thomas wrote, it's based on an very old ECMA Type 3, thats something like the "Mother Language" of some other languages, including Java Script. Because of that, I like to refer Java Script as some sort of "sister language" to extendScript, from whom you can borrow a lot.
So I'd suggest you read articles about object orientation (and classes) in general and Java Script in detail to get a better understanding about how (or why not, in that case) oop works in extendScript. But basically, it doesn't 😉 Thomas already posted the only suitable workaround, but it's still a workaround until adobe changes the codebase to something from this century.
https://www.w3schools.com/Js/js_classes.asp
https://www.youtube.com/watch?v=SiBw7os-_zI
Or, if you speak german, another really good explanation: https://www.youtube.com/watch?v=2le2YYr3N7s