Article View: adobe.scripting.indesign
Article #14908Re: [js] Problem with Objects
From: Jonathan_W_Brown
Date: Thu, 08 Jan 2004 23:48
Date: Thu, 08 Jan 2004 23:48
63 lines
3873 bytes
3873 bytes
This is the way InDesign works with JavaScript. For performance reasons, a variable containing an object stores a specifier to an object rather than the object itself. You can see what the specifier looks like using the "toSpecifier()" method. Accessing an object from a collection by subscript (as you are doing), creates a specifier that is relative to the location in the collection (as you put it, the variable is assigned to the array location). If the contents of the collection changes, then the specifier may refer to a different object. Whether creating a new object changes the contents of the collection depends on the type of object. For example, items in a page item collection (including text frames) are returned from front-to-back in the order the objects appear on the page. Since a new page item is created on top by default, the newest page item will appear at the beginning of the collection. (An example of an object that is added to the end of its collection by default is a spread.) Most objects (for example, those that have a unique id) can be forced to self-identify uniquely using the "getElements()" method, which retrieves (an array of) the object(s) referred to by a specifier at the time the method is invoked. Keep in mind, however, that some objects always use relative specifiers (e.g., text). Here's a script to see the difference between relative and unique specifiers: var doc = app.documents.add() ; //tfA is the unique specifier of a new text frame (A) var tfA = doc.textFrames.add() ; alert( "tfA = " + tfA.toSpecifier() ) ; //tfFIRST is a specifier to the first item in the collection var tfFIRST = doc.textFrames[0] ; alert( "tfFIRST = " + tfFIRST.toSpecifier() ) ; //tfFIRST_A is the unique specifier of the first item in the collection (A) var tfFIRST_A = tfFIRST.getElements()[0] ; alert( "tfFIRST_A = " + tfFIRST_A.toSpecifier() ) ; //tfB is the unique specifier of a new text frame (B) var tfB = doc.textFrames.add() ; alert( "tfB = " + tfB.toSpecifier() ) ; //tfFIRST is still a specifier to the first item in the collection alert( "tfFIRST = " + tfFIRST.toSpecifier() ) ; //tfFIRST_B is the unique specifier of the first item in the collection (B) var tfFIRST_B = tfFIRST.getElements()[0] ; alert( "tfFIRST_B = " + tfFIRST_B.toSpecifier() ) ; //tfSECOND is a specifier to the second item in the collection var tfSECOND = doc.textFrames[1] ; alert( "tfSECOND = " + tfSECOND.toSpecifier() ) ; //tfSECOND_A is the unique specifier of the second item in the collection (A) var tfSECOND_A = tfSECOND.getElements()[0] ; alert( "tfSECOND_A = " + tfSECOND_A.toSpecifier() ) ; //tfALL is a specifier to all items in the collection var tfALL = doc.textFrames.everyItem() ; alert( "tfALL = " + tfALL.toSpecifier() ) ; //tfALL_B is the unique specifier of the first item in the collection (B) var tfALL_B = tfALL.getElements()[0] ; alert( "tfALL_B = " + tfALL_B.toSpecifier() ) ; //tfALL_A is the unique specifier of the second item in the collection (A) var tfALL_A = tfALL.getElements()[1] ; alert( "tfALL_A = " + tfALL_A.toSpecifier() ) ;
Technical Details
Message-ID:
<p06020402bc23835e6f1d@[153.32.226.61]>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<2ccf3f6e.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,271beb45701319e6 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2004-01-08 16:07:50 PST From: Jonathan_W_Brown@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: Re: [js] Problem with Objects Message-ID: <p06020402bc23835e6f1d@[153.32.226.61]> Date: Thu, 8 Jan 2004 15:48:57 -0800 References: <2ccf3f6e.-1@webx.la2eafNXanI> Lines: 70 X-Sender: jwbrown@mailsea.sea.adobe.com MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit