Mike Chambers

code = joy

Playing a Sound from JavaScript in the Apollo Beta

with 7 comments

I just finished up a book I have been working on (along with Kevin Hoyt and Danny Dura) that covers using JavaScript and HTML to build Apollo applications. In celebration of finally writing my last example, I wanted to post it here.

Here is a simple example that shows how to use Flash Player and ActionScript APIs directly from JavaScript to play a sound in the upcoming Apollo beta.

<html>
<head>

	<script src="ApolloAliases.js" />
	<script type="text/javascript">

		function playSound()
		{
			var soundPath = new apollo.URLRequest("app-resource:/sound.mp3");
			var s = new apollo.Sound();
				s.load(soundPath);
				s.play();
		}
	</script>

</head>

<body>
	<input type="button" value="Play" onClick="playSound()">
</body>
</html>

It should be pretty self explanatory, and is a good example of how easy it is to use Flash and ActionScript APIs from JavaScript within Apollo applications.

Btw, ApolloAliases.js is a file included in the beta SDK that provides JavaScript aliases into ActionScript APIs to make them easier and more convenient to use from JavaScript.

Written by mikechambers

June 6th, 2007 at 12:11 am

Posted in air

7 Responses to 'Playing a Sound from JavaScript in the Apollo Beta'

Subscribe to comments with RSS or TrackBack to 'Playing a Sound from JavaScript in the Apollo Beta'.

  1. So easy my Grandma can do it…. thanks for the example.

    Mike Huntington

    6 Jun 07 at 1:05 am

  2. Mike – any details on this book? :-)

    David Bisset

    6 Jun 07 at 5:52 am

  3. Sweet! Thanks, Mike for posting this. And ditto @Mike Huntington….

    Kyle Hayes

    6 Jun 07 at 8:05 am

  4. When is the book set to be published?…

    Adam

    6 Jun 07 at 10:30 am

  5. Book should be out sometime in early July, although the PDF might be online (for free) earlier than that.

    mike chambers

    mesh@adobe.com

    mike chambers

    6 Jun 07 at 11:00 pm

  6. Nice one. Once PDF provided, please inform us. Thanks a lot.

    Alan_Ji

    8 Jun 07 at 6:03 am

  7. Hey. Excellent. I was at the PDX OnAir Tour and really am psyched about AIR and Flex.

    Can you use the example above to play a FLV file as well? What’s the code look like? What about all the FLV player attributes about size, etc?

    var videoPath = new apollo.URLRequest(“app-resource:/video.flv”);
    var s = new apollo.Video();
    s.load(videoPath);
    s.play();

    Brent

    14 Jul 07 at 8:20 am

Leave a Reply