How to publish SWF with Actionscript3 Audio?

183 Views Asked by At

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(); 
}
2

There are 2 best solutions below

0
Vesper On BEST ANSWER

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();
0
Sameer Kumar Jain On

You need to upload your mp3 files on ftp. Now the question is where should you upload. Lets take an example

Suppose you have swf located at htdocs/assets/swf/music.swf and that one loaded from the html located at htdocs/music.html. In that case you must upload your mp3 in htdocs directory.

A complex example where your swf loads mp3 from a directory for example mymusic/music.mp3, in that case your mp3 must be uploaded to htdocs/mymusic/music.mp3.

So all the paths to mp3 must be relative to the html files loading your swf, not to the relative to the swf location, unless you want to load swf in browser directly, without using html.