Expand my Community achievements bar.

SOLVED

Livecycle Script Objects with custom Javascript objects

Avatar

Former Community Member

Hi There,

I thought I'd try to write a Script Object with Objects and Classes that I could re-use throughout my form

In my Script Object "scoTest" I created a basic Object:

function TestObject()
{
    this.property1 = "a property";
    this.property2 = "b property";
}


However on a button click event calling:

var testObject = new scoTest.TestObject();
app.alert(testObject.property1);

Does not return anything

If I move the function definition (above) to the Click event (and remove the reference to the script object) - then I get the message box.

Is this part of the design of Livecycle?  Doesn't it severely limit the ability to write re-usable Object Classes?

1 Accepted Solution

Avatar

Correct answer by
Level 10

I've been frustrated by the same thing, there seems to be something very different about script objects and JavaScript in the form events.  Like you can't set breakpoints in script objects.

The work around I've used is to assign a variable in the event my constructor function and then create the object locally, so your script object would become

var Class = function TestObject()
{
    this.property1 = "a property";
    this.property2 = "b property";
}
Class.prototype.join = function()
{
return this.property1 + " and " + this.property2;
}

and the button event becomes

var scoTestClass = scoTest.Class;
var scoTestObject = new scoTestClass();
app.alert(scoTestObject.join());

An extra line but I do get re-usable objects

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

I've been frustrated by the same thing, there seems to be something very different about script objects and JavaScript in the form events.  Like you can't set breakpoints in script objects.

The work around I've used is to assign a variable in the event my constructor function and then create the object locally, so your script object would become

var Class = function TestObject()
{
    this.property1 = "a property";
    this.property2 = "b property";
}
Class.prototype.join = function()
{
return this.property1 + " and " + this.property2;
}

and the button event becomes

var scoTestClass = scoTest.Class;
var scoTestObject = new scoTestClass();
app.alert(scoTestObject.join());

An extra line but I do get re-usable objects

Avatar

Former Community Member

Ah great - that looks fine - quite an acceptable workaround

Thanks!