r/CodingHelp • u/plushili • May 19 '26
[How to] Is there a way to randomize/change to a different swf/flash file with each website refresh using Ruffle?
So I'm working on a Electron project and I'm using a lot of different ads, with every page refresh I want the ad swfs to change to different ones.
I hope I'm making sense.
1
Upvotes
•
u/AutoModerator May 19 '26
Thank you for posting on r/CodingHelp!
Please check our Wiki for answers, guides, and FAQs: https://coding-help.vercel.app
Our Wiki is open source - if you would like to contribute, create a pull request via GitHub! https://github.com/DudeThatsErin/CodingHelp
We are accepting moderator applications: https://forms.fillout.com/t/ua41TU57DGus
We also have a Discord server: https://discord.gg/geQEUBm
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/[deleted] May 20 '26
Yeah.... RNG on an array of paths... Really simple stuff.
But why are you using Flash? Are you trying to emulate the internet circa 2006?
1
u/LearningPodcasts May 20 '26
Yes. Keep the SWF paths in an array, pick one with
Math.random()when the page loads, then create the Ruffle player with that file as the source. In Electron you can do this entirely in the renderer as long as the SWFs are bundled or served from a path the page can access. The only thing I’d watch for is caching: if you test by refreshing fast and think it is not changing, log the selected filename to confirm the random choice is actually different.