Naming Objects And Attributes - Adobe GoLive CS2 Programmer's Manual

Hide thumbs Also See for GoLive CS2:
Table of Contents

Advertisement

SDK Programmer's Guide
attribute of the element becomes the name property of the object. Access to JavaScript properties is
case-sensitive; that is, the Thing attribute creates the Thing property, not the thing property. When
writing JavaScript code, observe case accordingly.
JavaScript uses the symbol undefined to indicate a null state. When a property exists, but no value has
been explicitly set, that property has a value of undefined . If a property has never been defined, its state
(rather than its value) is undefined . To test whether a property exists in JavaScript, you must test the
state (not the value), by checking whether the name has a defined type; for example:
// correct test
if (typeof (myProperty) != undefined)
// do something
Do not use the following test. This tests the property's value, rather than its state, and results in a run-time
error if the property does not exist:
// incorrect test
if (myProperty != undefined)
// if myProperty does not exist, an error occurs
When you must test a property's value with a case-sensitive comparison, you can use the toLowerCase
method of the JavaScript String object. For example, this tests an element object's tagName property,
disregarding the value's case:
if (currElt.tagName.toLowerCase()) == (tagToGet.toLowerCase())
For
element
markup tree. Use an element object's
attribute object, rather than accessing the attribute directly by name, as a property of the element object.
By using these methods, you avoid potential problems with referencing names that contain special
characters, such as hyphens.

Naming objects and attributes

The value of an element's name attribute must follow JavaScript naming conventions. If more than one
element or object uses the same name, the results of name-based object retrieval are unpredictable, so
you must take care to ensure that your names are unique. One way to do this is to use a unique prefix or
postfix in all of your extension's names. For example, the following element definitions begin the value of
each element's name attribute with the letters ADBE .
<jsxmenubar> // opens definition of all menus
<jsxmenu name="Hello" title="Hello, GoLive!"> // Hello menu
</jsxmenu> // closes definition of Hello menu
</jsxmenubar> // closes definition of all menus
When the SDK loads an extension containing these elements, it creates a menu object that appears in the
JavaScript global menus collection. You can use the name to retrieve this menu from the collection:
var myMenu = menubar["ADBEHello"];
Objects, attributes are also represented by objects, which are themselves nodes in the
<jsxitem name="This" title="Do Something"> // menu item
<jsxitem name="That" title="Do Something Else" > menu item
Adobe GoLive CS2 SDK
getAttributeNode
and
The JavaScript Environment
setAttributeNode
functions to access the
28

Advertisement

Table of Contents
loading

Table of Contents