I know that an embedded Flash/AS can access the page's DOM through the ExternalInterface class so I would imagine there is a way to do so using pure JavaScript as well. The embedded SVG will always be on the same domain so there should not be any security issues. Any help with finding a solution to this would be appreciated.
Here is some code to show what I mean (I have left out namespaces and such to simplify):
The SVG:
Code: Select all
<svg>
<script type="text/javascript">
//the audio element on the page
var audio = document.getElementById('theAudio');
//a function to instruct the audio element to play
function playAudio() {
audio.play();
}
</script>
<!-- A button to play the audio when clicked -->
<rect x="0" y="0" width="50px" height="50px" fill="black" onclick="playAudio()" />
</svg>
The HTML:
Code: Select all
<div>
<!-- The embedded SVG doc -->
<embed src="play_audio.svg" type="image/svg+xml" />
</div>
<!-- The Audio element -->
<audio id="theAudio" src="sound.wav" preload="auto">
Your browser does not support HTML5 audio.
</audio>