Extending ..extendscript
Is there a way to extend certain build in elements. Like you can add functinoality to arrays by :
Array.prototype.sum
I'd like to add functionality to the ScriptUI elemtns like groups/panels or text-elements.
Consider the following code:
function thedialog(){
dlg = new Window ('dialog', "Zum Tezts");
//this is the simple way
dlg.grpTools = dlg.add( 'group' );
//using function and sending the element
colorizeOne( dlg.grpTools, panelColors.red );
dlg.grpTools.add( 'statictext', [4,2,150,25], "this should be top" );
dlg.grpTools.ButtonDo = dlg.grpTools.add ('button', undefined, "Do me!");
//this is (imo) a better way
(dlg.grpHelp = dlg.add( 'group')).colorize = colorizeTwo;
//having this as part of the element itself
dlg.grpHelp.colorize( panelColors.blue );
dlg.grpHelp.add( 'statictext', [4,2,150,25], "this should be bottom" );
dlg.grpHelp.ButtonDo = dlg.grpHelp.add ('button', undefined, "No, do me!");
dlg.grpTools.ButtonDo.onClick = function( ){
dlg.grpHelp.colorize( panelColors.green );
colorizeOne (dlg.grpTools, panelColors.grey);
}
dlg.grpHelp.ButtonDo.onClick = function( ){
this.parent.colorize( panelColors.red );
colorizeOne (dlg.grpTools, panelColors.blue);
}
dlg.buttonCancel = dlg.add ('button', undefined, "Cancel");
dlg.show();
}
function colorizeOne( element, color ){
//alert(color);
element.graphics.backgroundColor = element.graphics.newBrush (element.graphics.BrushType.SOLID_COLOR,color);
}
function colorizeTwo( color ){
//alert(color);
this.graphics.backgroundColor = this.graphics.newBrush (this.graphics.BrushType.SOLID_COLOR,color);
}
var panelColors = {
grey : [0.5,0.5,0.5], //grey
blue : [0.5,0.5,0.7], //lila
green : [0.5,0.7,0.5], //green
red : [0.7,0.5,0.5], //red
}
//do it!
thedialog();
As you can see, I added the functionality to change color to the second group. Which is fine for our example, but what I REALLY want is for all groups and panels to adopt that behavior. Because having to add [element.colorize=colorize] every time makes the whole endavour a bit useless.
So, what I'm really looking for is something like:
ScriptUI.Group.prototype.setColor = colorize;Which is obviously not the right code..
Anyone know? Is there an easyer way I'm not seeing? Would LOVE prototype access to the core objects..
