English Deutsch 中文   




Using regular expressions to address multiple elements

From Garden Gnome Software

Jump to: navigation, search


Download the Skin
Download Video

Regular Expressions let you address multiple elements within the Skin Editor with just one action.
This will save time when setting up thumbnails or any other multiple element project.

Contents

Example Regular Expressions Project

  1. Add four Rectangles to the skin, 1 - 4, set each to alpha 0.5.

  2. In Rectangle 1 add the following actions:
    Mouse Enter, Change Element Alpha, Alpha: 1, Target: $self
    Mouse Enter, Change Element Alpha, Alpha: .5, Target: #Rectangle [2-4]

  3. In Rectangle 2 add the following actions:
    Mouse Enter, Change Element Alpha, Alpha: 1, Target: $self
    Mouse Enter, Change Element Alpha, Alpha: .5, Target: #Rectangle [1,3-4]

  4. In Rectangle 3 add the following actions:
    Mouse Enter, Change Element Alpha, Alpha: 1, Target: $self
    Mouse Enter, Change Element Alpha, Alpha: .5, Target: #Rectangle [1-2,4]

  5. In Rectangle 4 add the following actions:
    Mouse Enter, Change Element Alpha, Alpha: 1, Target: $self
    Mouse Enter, Change Element Alpha, Alpha: .5, Target: #Rectangle [1-3]

What will happen is that no matter which rectangle the mouse enters, the other three will fade out to alpha 0.5

Symbols used in the Regular Expressions

The following symbols can be used to modify the number range that needs to be addressed, so missing out certain numbers while including others.
1-3 means elements from range 1 to 3 are included.
1/3-4 means element 1 and 3 to 4, so 2 is not included.
A comma may also be used to separate the elements:
#Rectangle [1,3,4] will address Rectangles 1 and 3 and 4.
Note: the Target ID must be preceded with the pound/hash symbol, #

Use the pipe symbol, the vertical line, |, to separate element IDs. For example, to set two different elements to be visible:
Mouse Click, Show Element, Target: #Rectangle [1,3,4]|Button 2
Mouse Click, Show Element, Target: #Rectangle [1,3,4]|Button [2-8]

Using the Wild Card

The .* (asterisk) can be used to address all within a range:
Mouse Click, Hide Element, Target: #Rectangle .*
This will hide all rectangles in the skin.

Using more then one character to address many elements

So far the tip has looked at using a single character, numbers 1 to 9 or letters a to z. Using letters will address a maximum of 26 elements and numbers only 10 using 0 to 9.
If many elements in the skin need to be addressed then the vertical line, | (pipe) can be used as an OR. This also requires the variables to be encased in brackets, ( ).
Example
Mouse Click, Show Element, Target: #Rectangle (0[0-9]|1[0-9])
The above will address 00 to 19.
To address 00 to 29 add another OR block:
Mouse Click, Show Element, Target: #Rectangle (0[0-9]|1[0-9]|2[0-9])
Example of excluding Rectangle 15 and addressing all other Rectangles:
Mouse Click, Show Element, Target: #Rectangle (0[0-9]|1[0-4/6-9])
Of course using letters will let you address more elements, aa to bz will give you 52 elements that can be addressed.
Example of the naming convention in the Skin:
  • Rectangle aa
~
  • Rectangle az
  • Rectangle ba
~
  • Rectangle bz


Example of addressing all elements except for Rectangle bc.
Mouse Click, Show Element, Target: #Rectangle (a[a-z]|b[a,b/d-z])
To increase the amount of elements that can be addressed add another OR block.
Example:
Mouse Click, Show Element, Target: #Rectangle (a[a-z]|b[a-z]|c[a-z])
The above can address 78 skin elements in a single action, aa to cz

See also

Wikipedia:Regular expression

Using regular expressions in Actionscript 3



Printable version or PDF

This page was last modified on 29 March 2012, at 13:29.


© 2012 Garden Gnome Software