actionscript-3flashaudioadobeswfupload

How to publish SWF with Actionscript3 Audio?


I need to publish an AS3 assignment to a blog. My file uses four mp3 files saved in the same directory as the fla and swf files. It works fine in Adobe Animate CC when I "test movie"; but when I publish it to my blog, no music is audible. I'm assuming this is because the audio files are accessible on my laptop but not the internet.

Anyone know how to fix this?

Here is my code to attach the songs on my laptop to my fla file:

import flash.events.Event; 
import flash.media.Sound; 
import flash.net.URLRequest; 

var v:Sound = new Sound(); 
v.addEventListener(Event.COMPLETE, onSoundLoaded4); 
var req4:URLRequest = new URLRequest("excited.mp3"); 
v.load(req4); 

function onSoundLoaded4(event:Event):void 
{ 
var localSound4:Sound = event.target as Sound; 
localSound4.play(); 
}

Solution

  • As an alternate solution, you can embed the MP3s into your SWF by declaring them as resources to your FLA, assign them class names (base type will be Sound), then create instances of those classes instead of loading them from elsewhere. The downside is that your SWF will become a lot larger. An example (FlashDevelop syntax, to demonstrate embedding via code. To embed with Adobe Flash CS, use native mechanisms):

    [Embed(source = '../../lib/intro.mp3')] // relative path from AS to MP3
    private static const Intro:Class;
    ...
    var intro:Sound=new Intro();
    intro.play();