1

I have a simple <embed> tag for my flash animation in Chrome, and I want to swap out the animation dynamically:

<embed id="test" src="init.swf" width="550" height="400"> </embed>
<script>
    setTimeout(function() {
      document.getElementById("test").src = "test.swf";
      console.log("Swapped");
    }, 5000);
</script>

I expected init.swf to play for five seconds, before switching over to test.swf.

Instead, it keeps playing init.swf indefinitely. Meanwhile, the JS console shows Swapped, so the code is running. Even stranger, the element inspector shows the src tag updating, but the animation does not change.

Changing the width from either the inspector or my JS function works as expected, but src is not updated.

How can I replace this animation with another one?

that other guy
  • 116,971
  • 11
  • 170
  • 194
MilkyDeveloper
  • 608
  • 1
  • 6
  • 13
  • 4
    Show us your code! Otherwise the best I can do is point you towards `document.getElementById()`, and wish you luck! – Maximillian Laumeister Jan 30 '20 at 01:00
  • I'm sorry. ``` ``` is my code so far. – MilkyDeveloper Jan 30 '20 at 01:13
  • But it works fine if you hard-code the path in the `embed` element? – Maximillian Laumeister Jan 30 '20 at 01:20
  • Hey the result of `prompt("What is your swf file called?")` has single single quatation around it. So, first trim those quotes and then implant the result in your `embed`s src... Worked in my test. – ezio4df Jan 30 '20 at 02:00
  • 3
    It's time for you to embrace HTML5. – StackSlave Jan 30 '20 at 02:06
  • Welcome to SO! I was able to reproduce your problem in Chrome and took the liberty of editing your post with some additional details and an example that's easier to run (feel free to update if you don't find it representative). It appears that this may be a plugin integration issue rather than a problem with your code: see [this question](https://stackoverflow.com/questions/6646413/how-to-change-the-value-of-embed-src-with-javascript) which instead recommends swapping out the whole `` with a new one. – that other guy Jan 30 '20 at 03:28
  • @thatotherguy Could you please explain why the code you added does not match the OP's code? – Daedalus Jan 30 '20 at 03:31
  • 1
    @Daedalus-ReinstateMonica OP's code required typing in data which quickly became tedious in testing. The problem manifested with both dynamically entered and statically assigned strings. – that other guy Jan 30 '20 at 03:33

0 Answers0