Element Selector ($) (function)

Categories:Elements

Overview

Summary

The Item Selector function allows CSS-style selection of elements on stage.

Contents

 

Background

The

See the Selectors page for more info.

API

$(expression, context)

Element selector function

Parameters:

  • expression String A String expression
  • context String A path to a library Item
  • context Item A library Item
  • context Context A Context object with a valid item property

Returns:

  •   Array An array of library Items

The following example :

var elements = $(':bitmap');
as

The following example uses a context object to set the context of the selection prior to identifying the elements::

var elements = $(':bitmap');
as

Selectors

Property selectors

name

The following example matches any elements on stage whose name starts with the word Item:

$('Item*');

You can also limit selections using a range. The following example selects elements on stage named from "Item_01" to "Item_10":

$('Item_{1|10}');
:type

The type selector for the Element Selector matches both the elementType, and if the element has a corresponding library item, its itemType as well.

Valid elementTypes item types are:

  • :instance
  • :text
  • :shape
  • :shapeObj

Valid itemTypes are:

  • :movieclip
  • :graphic
  • :button
  • :symbol (matches :movieclip, :graphic or :button elements)
  • :bitmap
  • :component
  • :compiledclip
  • :video

The following example returns all movieclip items on stage on the current frame:

$(':movieclip');
[attribute]

The attribute selector matches elements' attributes name and optionally none, all or a part of their values. Full details for attribute can be found on the Selectors page.

The following example returns all elements on stage which are between 100 and 500 on the x axis:

$$('[left>100][left<500]);

The same result can also be acheived using a range:

$$('[left={100|500}]);	

Pseudo selectors

:keyframed

The keyframed selector matches all elements with keyframes other than frame 0;

$(':keyframed);
:animated

The animated selector matches all elements with tweens on at least one frame of their child timelines.

The following example matches items with :

$(':animated');
:scripted

The scripted selector matches all elements with scripts on at least one frame of their child timelines.

The following example matches items with :

$(':scripted');
:audible

The scripted selector matches all elements with sound on at least one frame of their child timelines.

The following example matches items with :

$(':audible');

 

 

3 Responses to Element Selector ($) (function)

  1. Nicolas Bousquet says:

    Another valid type would be ‘:font’ as well.

  2. Dave Stewart says:

    Well, :font isn’t a valid type for Stage elements, but it is for Library elements (check the $$ selector for :font!).

    It’s technically possible to add custom selectors to the selector engine to filter based on a sub property, i.e.:

    trace($selection[0].textRuns[0].textAttrs.face)

    I’ll need to look into that for the final release, and might even list/add some psuedo selectors for this kind of thing.

  3. Dave Stewart says:

    OK, see the latest blog post for an update on this!

    http://www.xjsfl.com/blog/custom-selectors

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>