1

I want a link to trigger a sound click in flash AS3. I've taken the .play() outside of the function to confirm that it works by itself. What am I missing that will let me call an AS3 function from javascript?

Here is my html

    <object width="5px" height="5px">
        <param name="movie" value="play_coin_sound/playCoin.swf?v=5">
        <param name="wmode" value="transparent">
        <embed src="play_coin_sound/playCoin.swf?v=5" width="5px" height="5px">
    </object>

    <span id="play-sound">Play Sound</span>

Here is my javascript

$('#play-sound').click(function(){ playCoin(); });

Here is my AS3 function

var coinSound:Sound = new Sound();
coinSound.load(new URLRequest("coin.mp3"));

function playCoin() {
    coinSound.play();
}

Any ideas?

1
  • Did do ExternalInterface.addCallBack("playCoin",playCoin) ?????? Commented Sep 7, 2011 at 23:54

3 Answers 3

1

If you are more comfortable with JavaScript than ActionScript, you could try using SoundManager:

"By wrapping and extending HTML5 and Flash Audio APIs, SoundManager 2 brings reliable cross-platform audio to JavaScript."

http://www.schillmania.com/projects/soundmanager2/

Edit: to clarify, SoundManager makes us of Flash when neccessary, like in browsers that don't support HTML5 audio, or if you want to use MP3 in browsers that don't support it.

Sign up to request clarification or add additional context in comments.

2 Comments

I would love to use something like this, but my click sound needs to work in IE's and non html5 compliant browsers.
With SoundManger, it will. That is the idea of it, to do "reliable cross-platform audio". In non HTML5 browsers, it makes use of Flash instead.
0

The following blogpost explains how to use the ExternalInterface class to listen for javascript function calls which will trigger AS3 functions. It provides examples of bid-directional communication.

http://www.viget.com/inspire/bi-directional-actionscript-javascript-communication/

Comments

0

This should put you right on track http://www.adobe.com/devnet/flash/articles/external_interface.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.