Sounds¶
A style sheet can attach a sound to a click, to the pointer entering an element, to focus arriving by key or gamepad, and to
the document's Back and close. The Sounds sample declares each one and counts clicks. Run it by choosing
Sounds in the samples list in the map L_ArcRmlSamples (Samples).
The properties¶
A sound is a MetaSound Source asset. To use your own, make one, right-click it in the Content Browser and choose
Copy Object Path (in the References section of the menu). Put asset: in front of the copied path and quote it:
/Game/Audio/MS_Click.MS_Click becomes "asset:/Game/Audio/MS_Click.MS_Click". The sample declares each property in
a style sheet:
body {
--sound-back: "asset:/ArcRmlUISamples/UI/Rml/Sounds/MS_Sample_Back.MS_Sample_Back";
--sound-close: "asset:/ArcRmlUISamples/UI/Rml/Sounds/MS_Sample_Back.MS_Sample_Back";
}
.sd-group {
--sound-click: "asset:/ArcRmlUISamples/UI/Rml/Sounds/MS_Sample_Click.MS_Sample_Click";
}
#sd-hover {
--sound-hover: "asset:/ArcRmlUISamples/UI/Rml/Sounds/MS_Sample_Click.MS_Sample_Click";
}
#sd-focus {
--sound-focus: "asset:/ArcRmlUISamples/UI/Rml/Sounds/MS_Sample_Click.MS_Sample_Click";
}
| Property | Declared on | Plays |
|---|---|---|
--sound-click |
any element | On a click from the mouse, gamepad accept or the keyboard. Once per click, from the clicked element or its nearest ancestor that declares it, so a parent's sound serves every button inside it. |
--sound-hover |
any element | Once when the pointer enters the declaring element; nothing while it moves inside it. |
--sound-focus |
any element | When the declaring element takes focus from a gamepad or the keyboard, including when a move enters its focus area. |
--sound-back |
body |
On a Back, the first step of Back, whether or not the Back then closes the document. |
--sound-close |
body |
When the document closes through data-action="close" or the close or toggle key. A Back that closes it plays only --sound-back. |
A property is never inherited: a child does not take its parent's value. The click sound is the one that still reaches
children, because the lookup runs from the clicked element up through its ancestors and the nearest one that declares
--sound-click plays. Hover and focus play only on the element that declares them: a child of a declaring
element does not play its parent's sound.
What you should see¶
In the Sounds sample, a click on any of the three buttons in the group plays the click sound and raises the Clicks count
by one. Entering the Hover button with the pointer plays a sound once, and so does moving focus to the Focus button with
an arrow key or the gamepad. Escape or gamepad back plays the back sound, and Close plays the close sound.
What stays silent¶
- Only gamepad and keyboard focus plays
--sound-focus. Focus from a mouse press is silent, and so is focus the plugin restores by itself: after the focused element disappears, onto a frame's selected tab, and back to a parent area after a Back (only the back sound plays). - A keep-alive document that is opened again focuses the element that takes focus on open and plays that element's
--sound-focuseach time (Documents).
The compile errors¶
The document compile fails for a --sound-* declaration that:
- is not a quoted literal
"asset:/Package/Path.Object": an unquoted value, another prefix, or avar(); - names an asset that does not exist;
- names an asset that is not a MetaSound Source (the message names the class it found).
Limits
- Declare sounds in a style sheet. An inline
style=""declaration is read as a texture reference and fails to compile. - Only a MetaSound Source plays; a sound wave or a cue is a compile error.
- Every property whose name starts with
--sound-is read as a sound, so a custom property of your own must not use that prefix.