Item Selector ($$) (function)
Overview
Summary
The Item Selector function allows CSS-style selection of elements on stage.
Contents
Usage
See the Selectors page for more info.
API
$(expression, context)
Library Item selector function
The following example :
functio(expression, context);
Selectors
Property selectors
name
The name selector returns items with the specified name.
Wildcards and ranges can be used with name selectors.
The following example matches any items whose name contains the word button:
$$('*button*');
/path
The path selector returns items of the specified itemType. Valid item types are:
Wildcards and ranges can be used with path selectors.
The following example matches all desendants in the folder /assets/bitmaps:
$$('/assets/bitmaps/*');
:type
The type selector returns items of the specified itemType. Valid item types are:
- :movieclip
- :graphic
- :button
- :symbol (matches :movieclip, :graphic or :button elements)
- :folder
- :font
- :sound
- :bitmap
- :component
- :compiledclip
- :screen
- :video / :embeddedvideo / :linkedvideo
The following example returns all graphic elements in and below the assets/ folder:
$$('assets/*:graphic');
.Class (uppercase first-letter)
The class selector matches all items set to export to a particular class.
Wildcards can be used with class selectors.
The following example matches items named 'dave':
$$('.*Button);
.package (lowercase first-letter)
Wildcards can be used with name selectors.
The following example matches all items set to export to the package com.xjsfl.ui and below:
$$('.com.xjsfl.ui.*');
[attribute]
The attribute selector matches elements by attribute - see the Selectors page for full details.
The following example returns an ItemCollection with all bitmap items that have their allowSnoothing property set to false:
$$(':bitmap[allowSmoothing=false]);
Structural selectors
:children
The children selector matches all immediate children of the currently-matched folders, rather than all descendants.
The following example matches items with :
$$('/path/to/folder:children');
:descendants
The descendents selector matches all items below the currently-matched folders. Note that descendants is spelled with an a not an e !
The following example matches items with :
$$('/assets:descendants');
You can get the same result with a wildcard operator (removing the trailing slash would return the parent folder as well):
$$('/assets/*');
:parent
The parent selector matches the parent folder of all current items.
The following example matches all current items with :
$$(':bitmap:parent');
To get a grandparent, just double-up the selector
var grandparent = $$(':bitmap:parent:parent');
Pseudo selectors
:exported
The following example matches items with :
$$(':exported');
:empty
The empty selector matches:
- folders without and child items
- movieclips, graphics or buttons without any elements on stage
To limit the match to only folders, use the :folder type selector as well.
The following example matches empty folders in the library:
$$(':folder:empty');
See the Working with items page for the code to recursively delete nested empty folders from the library.
Element Selector types
Given that Items are themselves elements the following element pseudo-selectors are valid:
Combination selectors
:contains(selector)
The contains selector looks inside items and attempts to match the supplied selector. This means you can easily find library items that contain other items, named items, classes and so on.
The following example matches movieclips containing instances of the library item red_button:
$$(':movieclip:contains(/assets/buttons/red_button)');
The following example matches movieclips containing named items on stage called blue button:
$$(':movieclip:contains(blue_button)');