#✅ | Hello I want to know how to...
1 messages · Page 1 of 1 (latest)
You can’t automatically “fade” audio in one built‑in action, but you can simulate it with a tiny action script that repeatedly nudges each audio element’s volume via set_audio_element_volume.
How to set it up
- Put your main background music in a universal layout (auto‑playing audio element); give it an easy ID like
main_music. - Create the screen‑specific layout and add that second audio element (e.g.,
screen_music). Enable it only for that screen. - Add a Ticker (or use a listener) that runs while the screen layout is active. In its action script you’ll:
- Read the current volumes with the
audio_element_volplaceholder. - On screen open, lower
main_musicin small steps and raisescreen_musicin small steps by repeatedly callingset_audio_element_volumewith calculated values. - When the screen closes (or when your layout unloads), reverse the steps to bring
main_musicback up and fadescreen_musicdown.
- Read the current volumes with the
A simple pattern is this:
IF current_volume(main_music) > target_main
set_audio_element_volume -> new_volume = current - 0.05
ELSE
set_audio_element_volume -> target value (e.g., 0)
You can use the audio_element_vol placeholder to fetch each element’s current volume and compare it in Is Number requirements. Run the ticker every 50–100 ms to make the fade smooth. Do the same flipped logic for screen_music (raise toward 1.0 while lowering the other).
If you prefer not to script the whole fade, you can simply trigger the set_audio_element_volume action twice (once to mute the other track, once to bring the new one to 100%) when the screen opens/closes. That’s faster but less smooth.
Need the exact action and placeholder names? Check the Action Scripts guide for set_audio_element_volume and the Placeholders page for audio_element_vol.
can you provide me a complete and detailed example of how to do that?
Sure! Here’s a full example of how to simulate fading between your universal background music and a screen‑specific track using a Ticker + action script.
1. Audio setup
- Universal layout: add an Audio element (ID
main_music) with your main track. Set it to play automatically and loop. - Screen layout: add another Audio element (ID
screen_music) with the screen-specific track. Let it autoplay when that layout loads.
2. Create a Ticker element
Place a Ticker element in the screen layout. Set it to tick frequently (e.g., tick delay 100 ms) and run “Normal” or “On Screen Load” mode so it updates while the screen is open.
3. Fade action script (ticker)
Right-click the ticker → Edit Action Script. Use this structure:
▶ IF – Is Number (compare $$value placeholder to 0.05) checking `audio_element_vol` for main_music
└─ Set Audio Element Volume: `main_music:{"placeholder":"calc","values":{"expression":"{"placeholder":"audio_element_vol","values":{"element_identifier":"main_music"}} - 0.05","decimal":"true"}}`
▶ ELSE
└─ Set Audio Element Volume: `main_music:0.0`
▶ IF – Is Number (compare to < 0.95) using `audio_element_vol` for screen_music
└─ Set Audio Element Volume: `screen_music:{"placeholder":"calc","values":{"expression":"{"placeholder":"audio_element_vol","values":{"element_identifier":"screen_music"}} + 0.05","decimal":"true"}}`
▶ ELSE
└─ Set Audio Element Volume: `screen_music:1.0`
- The
audio_element_volplaceholder (see Placeholders) reads the current volume. - The
calcplaceholder increments/decrements by0.05per tick; adjust the step or delay for smoother/faster fades. - Add
Is Numberrequirements to keep the actions from overshooting (e.g., compare current volume with> 0.0or< 1.0).
4. Fade back when screen closes
Use either:
- Screen Close listener/action: add a ticker or listener that detects when the layout unloads (e.g., toggle a layout requirement or use a listener
On Screen Closed) and reverse the logic (fadescreen_musicdown while fadingmain_musicup). - Or have a
General Tickerrunning in a universal layout that checks if the screen’s layout is active (via a variable orIs Layout Enabledrequirement) and applies the opposite fade.
5. Optional: store target volumes in variables
If you want to reuse steps for multiple screens, store target volumes (target_main, target_screen) in variables and only run the fade logic when those targets change.
📘 For more details see the Action Scripts guide (especially set_audio_element_volume) and the Placeholders list for audio_element_vol/calc.
Would you like me to help you build the exact ticker script with placeholder JSON you can paste in?
Provide me any troubleshooting guide of what have i to check in case it wasn't working
Here’s a quick troubleshooting checklist for when your music fade setup doesn’t work:
-
Confirm your audio IDs
Make sure the IDs you use in actions/placeholders match the actual element identifiers (right-click → “Copy Element Identifier”). Wrong IDs meanset_audio_element_volumeandaudio_element_volfail silently. -
Check ticker is running
- Ticker tick delay should be low (e.g., 100 ms).
- Tick mode must actually run while the screen is open (use “Normal” or “Tick While Screen Open”).
-
Verify requirements let the actions fire
If you gate the fade logic withIs Numberrequirements, ensure they evaluate correctly. Catch edge cases by logging viaPrint to Logor temporarily removing requirements. -
Watch for volume clamping
If yourcalcexpression keeps going below 0 or above 1, addIs Numberrequirements like “current_volume > 0.0” or “< 1.0” before adjusting, so the value stops at 0/1. -
Ensure both audio elements are enabled
The screen-specific audio must be loaded when the ticker runs (check layout loading requirements). If it hasn’t loaded,audio_element_volreturns nothing. -
Use placeholders & actions from docs
Reference Action Scripts forset_audio_element_volumeand Placeholders foraudio_element_vol/calcto ensure you’re supplying valid JSON. -
Test without fading logic
Temporarily set fixed volumes (e.g., setmain_music:0andscreen_music:1) to verify the action path itself works before adding the fade loop.
If anything still acts up, describe what’s happening (e.g., “main music never fades out”) and I’ll suggest more targeted tweaks ☁️
This support thread has been marked as solved by @rose idol.
The AI helper is now disabled, but you can still continue the conversation if needed. Thank you for using our support system!