Skip to main content
Participating Frequently
June 13, 2012
Question

Sounds don't play on iPhone

  • June 13, 2012
  • 12 replies
  • 1387 views

Good morning, I developed a simple soundboard as an .ipa app with AIR for iOS, but the sounds don't work. I mean, when I open the app I can see the buttons to push to play the relative sound, but when I push a button the sound doesn't play.

Here is my AS:

import flash.text.TextField;

//Array for buttons instances.

var buttonsArray:Array = new Array();

buttonsArray[0] = a01;

buttonsArray[1] = a02;

buttonsArray[2] = a03;

//Array for the sound clip names.

var soundArray:Array = new Array();

soundArray[0] = 'media/a01.mp3';

soundArray[1] = 'media/a02.mp3';

soundArray[2] = 'media/a03.mp3';

//This adds the mouse click event to the buttons.

for(var i:uint = 0; i < buttonsArray.length; i++){

buttonsArray.addEventListener(MouseEvent.CLICK, buttonClicked);

}

astop.addEventListener(MouseEvent.CLICK, stopButtonClicked);

//This function stops any sound clip that is playing and

//plays the sound file thats clicked.

function buttonClicked(e:MouseEvent):void{

SoundMixer.stopAll();

for(var i:uint = 0; i < buttonsArray.length; i++){

  if(e.target == buttonsArray){

   var s:Sound = new Sound();

   s.load(new URLRequest(soundArray));

   s.play();

  }

}

}

//This function adds a keyboard down event to the stage

//to stop a sound when the space bar is pressed.

function stopButtonClicked(e:MouseEvent):void{

SoundMixer.stopAll();

}

The same thing happens when I export this file as an .exe.

What am I missing?

This topic has been closed for replies.

12 replies

Inspiring
June 13, 2012

I know this may not be the answer you are looking for, but have you tried to include the sounds in the app via swc? I personally have never tried playing external sounds on iOS, but embeded sounds work just fine!

Participating Frequently
June 13, 2012

Sorry for the noob question, but can you explain the steps to do what you suggested?

Thanks in advance

Or just give me a link to a good tutorial...

Inspiring
June 13, 2012

Sure thing!

1. Create new FLA

2. Import the sounds you want to use into your library

3. Right click on the sounds in your library > Properties > Actionscript > Make sure to check "Export for Actionscript". (you can also rename the "Class" part to something easier to remember, just make sure you remember it) > Hit OK

4. File > Publish Settings > Now un-check  the "Flash (.swf)" option, and check the "SWC" option. Hit OK> then Publish.

You now will have a .swc file that you will include in the source of your project..

now the only thing left is to use the swc.

EX:

var mySound:Sound = new MyClassNameIRememberedFromBefore();

mySound.play();

Colin Holgate
Inspiring
June 13, 2012

Did you add the media folder in the General iOS settings?

Participating Frequently
June 13, 2012

Yes, but nothing happend: the sounds still don't play.