library object

 < Day Day Up > 

Availability

Flash MX 2004.

Description

The library object represents the Library panel. It is a property of the Document object (see document.library) and can be accessed by fl.getDocumentDOM().library.

The library object contains an array of items of different types, including symbols, bitmaps, sounds, and video.

Method summary for the library object

The following methods are available for the library object:

Method

Description

library.addItemToDocument()

Adds the current or specified item to the Stage at the specified position.

library.addNewItem()

Creates a new item of the specified type in the Library panel and sets the new item to the currently selected item.

library.deleteItem()

Deletes the current items or a specified item from the Library panel.

library.duplicateItem()

Makes a copy of the currently selected or specified item.

library.editItem()

Opens the currently selected or specified item in Edit mode.

library.expandFolder()

Expands or collapses the currently selected or specified folder in the library.

library.findItemIndex()

Returns the library item's index value (zero-based).

library.getItemProperty()

Gets the property for the selected item.

library.getItemType()

Gets the type of object currently selected or specified by a library path.

library.getSelectedItems()

Gets the array of all currently selected items in the library.

library.importEmbeddedSWF()

Imports a Shockwave (SWF) file into the library as a compiled clip.

library.itemExists()

Checks to see if a specified item exists in the library.

library.moveToFolder()

Moves the currently selected or specified library item to a specified folder.

library.newFolder()

Creates a new folder with the specified name, or a default name ("untitled folder #") if no folderName parameter is provided, in the currently selected folder.

library.renameItem()

Renames the currently selected library item in the Library panel.

library.selectAll()

Selects or deselects all items in the library.

library.selectItem()

Selects a specified library item.

library.selectNone()

Selects all the library items.

library.setItemProperty()

Sets the property for all selected library items (ignoring folders).

library.updateItem()

Updates the specified item.


Property summary for the library object

The following property is available for the library object.

Property

Description

library.items

An array of item objects in the library


library.addItemToDocument()

Availability

Flash MX 2004.

Usage

library.addItemToDocument( position [, namePath] )

Parameters

position A point that specifies the x,y position of the center of the item on the Stage.

namePath A string that specifies the name of the item. If the item is in a folder, you can specify its name and path using slash notation. If namePath is not specified, the current library selection is used. This parameter is optional.

Returns

A Boolean value: TRue if the item is successfully added to the document; false otherwise.

Description

Method; adds the current or specified item to the Stage at the specified position.

Example

The following example adds the currently selected item to the Stage at the (3, 60) position:

fl.getDocumentDOM().library.addItemToDocument({x:3, y:60});

The following example adds the item Symbol1 located in folder1 of the library to the Stage at the (550, 485) position:

fl.getDocumentDOM().library.addItemToDocument({x:550.0, y:485.0}, "folder1/   Symbol1");

library.addNewItem()

Availability

Flash MX 2004.

Usage

library.addNewItem( type [, namePath] )

Parameters

type A string that specifies the type of item to create. The only acceptable values for type are "video", "movie clip", "button", "graphic", "bitmap", "screen", and "folder" (so, for example, you cannot add a sound to the library with this method). Specifying a folder path is the same as using library.newFolder() before calling this method.

namePath A string that specifies the name of the item to be added. If the item is in a folder, specify its name and path using slash notation. This parameter is optional.

Returns

A Boolean value: true if the item is successfully created; false otherwise.

Description

Method; creates a new item of the specified type in the Library panel and sets the new item to the currently selected item. For more information on importing items into the library, including items such as sounds, see document.importFile().

Example

The following example creates a new button item named start in a new folder named folderTwo:

fl.getDocumentDOM().library.addNewItem("button", "folderTwo/start");

library.deleteItem()

Availability

Flash MX 2004.

Usage

library.deleteItem( [namePath] )

Parameters

namePath A string that specifies the name of the item to be deleted. If the item is in a folder, you can specify its name and path using slash notation. If you pass a folder name, the folder and all its items are deleted. If no name is specified, Flash deletes the currently selected item or items. To delete all the items in the Library panel, select all items before using this method. This parameter is optional.

Returns

A Boolean value: true if the items are successfully deleted; false otherwise.

Description

Method; deletes the current items or a specified item from the Library panel. This method can affect multiple items if several are selected.

Example

The following example deletes the currently selected item:

fl.getDocumentDOM().library.deleteItem();

The following example deletes the item Symbol_1 from the library folder Folder_1:

fl.getDocumentDOM().library.deleteItem("Folder_1/Symbol_1");

library.duplicateItem()

Availability

Flash MX 2004.

Usage

library.duplicateItem( [namePath] )

Parameters

namePath A string that specifies the name of the item to duplicate. If the item is in a folder, you can specify its name and path using slash notation. This parameter is optional.

Returns

A Boolean value: TRue if the item is duplicated successfully; false otherwise. If more than one item is selected, Flash returns false.

Description

Method; makes a copy of the currently selected or specified item. The new item has a default name (such as item copy) and is set as the currently selected item. If more than one item is selected, the command fails.

Example

The following example creates a copy of the item square in the library folder test:

fl.getDocumentDOM().library.duplicateItem("test/square");

library.editItem()

Availability

Flash MX 2004.

Usage

library.editItem( [namePath] )

Parameters

namePath A string that specifies the name of the item. If the item is in a folder, you can specify its name and path using slash notation. If namePath is not specified, the single selected library item opens in Edit mode. If none or more than one item in the library is currently selected, the first scene in the main timeline appears for editing. This parameter is optional.

Returns

A Boolean value: TRue if the specified item exists and can be edited; false otherwise.

Description

Method; opens the currently selected or specified item in Edit mode.

Example

The following example opens the item circle in the test folder of the library for editing:

fl.getDocumentDOM().library.editItem("test/circle");

library.expandFolder()

Availability

Flash MX 2004.

Usage

library.expandFolder(bExpand [, bRecurseNestedParents [, namePath ] ] )

Parameters

bExpand A Boolean value: if true, the folder is expanded; if false (the default), the folder is collapsed.

bRecurseNestedParents A Boolean value: if true, all the folders within the specified folder are expanded or collapsed, based on the value of bExpand. The default value is false. This parameter is optional.

namePath A string that specifies the name and, optionally, the path of the folder to expand or collapse. If this parameter is not specified, the method applies to the currently selected folder. This parameter is optional.

Returns

A Boolean value: true if the item is successfully expanded or collapsed; false if unsuccessful or the specified item is not a folder.

Description

Method; expands or collapses the currently selected or specified folder in the library.

Example

The following example collapses the test folder in the library as well as all the folders within the test folder (if any):

fl.getDocumentDOM().library.expandFolder(false, true, "test");

library.findItemIndex()

Availability

Flash MX 2004.

Usage

library.findItemIndex(namePath)

Parameters

namePath A string that specifies the name of the item. If the item is in a folder, you can specify its name and path using slash notation.

Returns

An integer value representing the item's zero-based index value.

Description

Method; returns the library item's index value (zero-based). The library index is flat, so folders are considered part of the main index. Folder paths can be used to specify a nested item.

Example

The following example stores the zero-based index value of the library item square, which is in the test folder, in the variable sqIndex, and then displays the index value in a dialog box:

var sqIndex = fl.getDocumentDOM().library.findItemIndex("test/square"); alert(sqIndex);

library.getItemProperty()

Availability

Flash MX 2004.

Usage

library.getItemProperty( property )

Parameters

property A string. For a list of values that you can use as a property parameter, see the Property summary for the Item object, along with property summaries for its subclasses.

Returns

A string value for the property.

Description

Method; gets the property for the selected item.

Example

The following example shows a dialog box that contains the Linkage Identifier value for the symbol when referencing it using ActionScript or for runtime sharing:

alert(fl.getDocumentDOM().library.getItemProperty("linkageIdentifier"));

library.getItemType()

Availability

Flash MX 2004.

Usage

library.getItemType( [namePath] )

Parameters

namePath A string that specifies the name of the item. If the item is in a folder, specify its name and path using slash notation. If namePath is not specified, Flash provides the type of the current selection. If more than one item is currently selected and no namePath is provided, Flash ignores the command. This parameter is optional.

Returns

A string value specifying the type of object. For possible return values, see item.itemType.

Description

Method; gets the type of object currently selected or specified by a library path.

Example

The following example shows a dialog box that contains the item type of Symbol_1 located in the Folder_1/Folder_2 folder:

alert(fl.getDocumentDOM().library.getItemType("Folder_1/Folder_2/   Symbol_1"));

library.getSelectedItems()

Availability

Flash MX 2004.

Parameters

None.

Returns

An array of values for all currently selected items in the library.

Description

Method; gets the array of all currently selected items in the library.

Example

The following example stores the array of currently selected library items (in this case, several audio files) in the selItems variable and then changes the sampleRate property of the first audio file in the array to "11 kHz":

var selItems = fl.getDocumentDOM().library.getSelectedItems(); selItems[0].sampleRate = "11 kHz";

library.importEmbeddedSWF()

Availability

Flash MX 2004.

Usage

library.importEmbeddedSWF(linkageName, swfData [, libName] )

Parameters

linkageName A string that provides the name of the SWF linkage of the root movie clip.

swfData An array of binary SWF data, which comes from an external library or DLL.

libName A string that specifies the library name for the created item. If the name is already used, the method creates an alternate name. This parameter is optional.

Returns

Nothing.

Description

Method; imports a Shockwave (SWF) file into the library as a compiled clip. Unlike File > Import > SWF, this method lets you embed a compiled SWF file inside the library. There is no corresponding user interface functionality, and this method must be used with an external library or DLL (see Chapter 3, "C-Level Extensibility," on page 533).

The SWF file that you are importing must have one top-level movie clip that contains all the content. That movie clip should have its linkage identifier set to the same value as the linkageName parameter passed to this method.

Example

The following example adds the SWF file with the linkageName value of MyMovie to the library as a compiled clip named Intro:

fl.getDocumentDOM().library.importEmbeddedSWF("MyMovie", swfData, "Intro");

library.itemExists()

Availability

Flash MX 2004.

Usage

library.itemExists( namePath )

Parameters

namePath A string that specifies the name of the item. If the item is in a folder, specify its name and path using slash notation.

Returns

A Boolean value: true if the specified item exists in the library; false otherwise.

Description

Method; checks to see if a specified item exists in the library.

Example

The following example displays true or false in a dialog box, depending on whether the item Symbol_1 exists in the Folder_1 library folder:

alert(fl.getDocumentDOM().library.itemExists('Folder_1/Symbol_1'));

library.items

Availability

Flash MX 2004.

Usage

library.items

Description

Property; an array of item objects in the library.

Example

The following example stores the array of all library items in the itemArray variable:

var itemArray = fl.getDocumentDOM().library.items;

library.moveToFolder()

Availability

Flash MX 2004.

Usage

library.moveToFolder( folderPath [, itemToMove [, bReplace ] ] )

Parameters

folderPath A string that specifies the path to the folder in the form "FolderName" or "FolderName/FolderName". To move an item to the top level, specify an empty string ("") for folderPath.

itemToMove A string that specifies the name of the item to move. If itemToMove is not specified, the currently selected items move. This parameter is optional.

bReplace A Boolean value. If an item with the same name already exists, specifying true for the bReplace parameter replaces the existing item with the item being moved. If false, the name of the dropped item changes to a unique name. The default value is false. This parameter is optional.

Returns

A Boolean value: TRue if the item moves successfully; false otherwise.

Description

Method; moves the currently selected or specified library item to a specified folder. If the folderPath parameter is empty, the items move to the top level.

Example

The following example moves the item Symbol_1 to the library folder new and replaces the item in that folder with the same name:

fl.getDocumentDOM().library.moveToFolder("new", "Symbol_1", true);

library.newFolder()

Availability

Flash MX 2004.

Usage

library.newFolder( [folderPath] )

Parameters

folderPath A string that specifies the name of the folder to be created. If it is specified as a path, and the path doesn't exist, the path is created. This parameter is optional.

Returns

A Boolean value: true if folder is created successfully; false otherwise.

Description

Method; creates a new folder with the specified name, or a default name ("untitled folder #") if no folderName parameter is provided, in the currently selected folder.

Example

The following example creates two new library folders; the second folder is a subfolder of the first folder:

fl.getDocumentDOM().library.newFolder("first/second");

library.renameItem()

Availability

Flash MX 2004.

Usage

library.renameItem(name)

Parameters

name A string that specifies a new name for the library item.

Returns

A Boolean value of TRue if the name of the item changes successfully, false otherwise. If multiple items are selected, no names are changed, and the return value is false (to match user interface behavior).

Description

Method; renames the currently selected library item in the Library panel.

Example

The following example renames the currently selected library item to new name:

fl.getDocumentDOM().library.renameItem("new name");

library.selectAll()

Availability

Flash MX 2004.

Usage

library.selectAll( [ bSelectAll ] )

Parameters

bSelectAll A Boolean value that specifies whether to select or deselect all items in the library. Omit this parameter or use the default value of TRue to select all the items in the library; false deselects all library items. This parameter is optional.

Returns

Nothing.

Description

Method; selects or deselects all items in the library.

Example

The following examples select all the items in the library:

fl.getDocumentDOM().library.selectAll(); fl.getDocumentDOM().library.selectAll(true);

The following examples deselect all the items in the library:

fl.getDocumentDOM().library.selectAll(false); fl.getDocumentDOM().library.selectNone();

library.selectItem()

Availability

Flash MX 2004.

Usage

library.selectItem( namePath [, bReplaceCurrentSelection [, bSelect ] ] )

Parameters

namePath A string that specifies the name of the item. If the item is in a folder, you can specify its name and path using slash notation.

bReplaceCurrentSelection A Boolean value that specifies whether to replace the current selection or add the item to the current selection. The default value is true (replace current selection). This parameter is optional.

bSelect A Boolean value that specifies whether to select or deselect an item. The default value is true (select). This parameter is optional.

Returns

A Boolean value: true if the specified item exists; false otherwise.

Description

Method; selects a specified library item.

Example

The following example changes the current selection in the library to symbol 1 inside untitled folder 1:

fl.getDocumentDOM().library.selectItem("untitled Folder_1/Symbol_1");

The following example extends what is currently selected in the library to include symbol 1 inside untitled folder 1:

fl.getDocumentDOM().library.selectItem("untitled Folder_1/Symbol_1",   false);

The following example deselects symbol 1 inside untitled folder 1 and does not change other selected items:

fl.getDocumentDOM().library.selectItem("untitled Folder_1/Symbol_1", true,   false);

library.selectNone()

Availability

Flash MX 2004.

Parameters

None.

Returns

Nothing.

Description

Method; deselects all the library items.

Example

The following examples deselect all the items in the library:

fl.getDocumentDOM().library.selectNone(); fl.getDocumentDOM().library.selectAll(false);

library.setItemProperty()

Availability

Flash MX 2004.

Usage

library.setItemProperty( property, value )

Parameters

property A string that is the name of the property to set. For a list of properties, see the Property summary for the Item object and property summaries for its subclasses. To see which objects are subclasses of the Item object, see Summary of the DOM structure.

value The value to assign to the specified property.

Returns

Nothing.

Description

Method; sets the property for all selected library items (ignoring folders).

Example

The following example assigns the value button to the symbolType property for the selected library item or items. In this case, the item must be a SymbolItem object; symbolType is a valid property for SymbolItem objects.

fl.getDocumentDOM().library.setItemProperty("symbolType", "button");

library.updateItem()

Availability

Flash MX 2004.

Usage

library.updateItem( [ namePath ] )

Parameters

namePath A string that specifies the name of the item. If the item is in a folder, specify its name and path using slash notation. This is the same as right-clicking on an item and selecting Update from the menu in the user interface. If no name is provided, the current selection is updated. This parameter is optional.

Returns

A Boolean value: TRue if Flash updated the item successfully; false otherwise.

Description

Method; updates the specified item.

Example

The following example displays a dialog box that shows whether the currently selected item is updated (TRue) or not (false):

alert(fl.getDocumentDOM().library.updateItem());

     < Day Day Up > 


    Developing Extensions for Macromedia Flash 8
    Developing Extensions for Macromedia Flash 8
    ISBN: 032139416X
    EAN: 2147483647
    Year: 2005
    Pages: 81

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net