A problem with prototyped functions and menu items

Upload Adobe Bridge Scripts, Download Adobe Bridge Scripts, Support for Individual Adobe Bridge Scripts

Moderators: Tom, Kukurykus

miked

A problem with prototyped functions and menu items

Post by miked »

I can't seem to call a prototyped function when a menu item is selected. For example, when the following code is saved into Bridges Startup Scripts folder and Bridge is run, "fie" is displayed (that verifies prototyped functions work). Next, if "Run My Command" is selected from the Tools menu, "foo" is shown but "bar" is not. (Note that this code is based on code from the Bridge SDK, except for the prototyped function call in onSelect().)

Code: Select all#target bridge

function CP_addMenuItem() {
    // The unique identifier for the menu item
    this.menuCommandID = "cpCommandID";
}

CP_addMenuItem.prototype.run = function() {
    // Create the menu item
    var alertCommand = new MenuElement( "command", "Run My Command", "-at the end of Tools", this.menuCommandID );

    this.fie(); // this prototyped function works

    // Define the behavior (what happens when the item is selected)
    alertCommand.onSelect = function () {
   foo(); // this normal non-prototyped function works
   this.bar(); // this prototyped function does not work. WTF?
    }
}

function foo () {
    alert ("foo");
}

CP_addMenuItem.prototype.bar = function( ) {
    alert("bar");
}
CP_addMenuItem.prototype.fie = function( ) {
    alert("fie");
}

new CP_addMenuItem().run();


Is there some syntax issue I am unaware of, and that the manual is not spelling out? Or is this just not possible?

...Mike