Skip to main content
Participating Frequently
April 21, 2013
Question

playing sound

  • April 21, 2013
  • 2 replies
  • 413 views

heya need some help got some sound that i need to be played when qued

i want the sound to be played in 'var moveSound:Array'

Any fixes? or does any know how to solve my problem?

import flash.events.MouseEvent;

addChild(btnPos1U);

btnPos1U.x=btnPos1U.y=0;

var positionA:Array=[[0,0],

                     [0,stage.stageHeight-btnPos1U.height],

                     [stage.stageWidth-btnPos1U.width,0],

                     [stage.stageWidth-btnPos1U.width,stage.stageHeight-btnPos1U.height]];

var moveSound:Array = ["1.wav","2.mp3","3.wav","4.oga"];

var t:Timer=new Timer(2000,0);

t.addEventListener(TimerEvent.TIMER,f);

t.start();

function f(e:TimerEvent):void{

   

btnPos1U.visible = true;

var nQuadrant = Math.floor(Math.random()* 4); // generates [0..3]

btnPos1U.x=positionA[nQuadrant][0];

btnPos1U.y=positionA[nQuadrant][1];

var sAudioName:String = moveSound[nQuadrant];

// ... and now run the sound fx ...

//btnPos1U.x=Math.floor(Math.random()*(stage.stageWidth-btnPos1U.width));

//btnPos1U.y=Math.floor(Math.random()*(stage.stageHeight-btnPos1U.height));

}

btnPos1U.addEventListener(MouseEvent.CLICK,g)

function g (e:MouseEvent):void

{

    btnPos1U.visible = false

}

    init();

    btnNeg1.addEventListener(MouseEvent.CLICK, EndUnlimited);

    btnNeg2.addEventListener(MouseEvent.CLICK, EndUnlimited);

    btnNeg3.addEventListener(MouseEvent.CLICK, EndUnlimited);

    btnNeg4.addEventListener(MouseEvent.CLICK, EndUnlimited);

    

   

    btnPos1U.addEventListener(MouseEvent.CLICK, on_press);

function EndUnlimited (e:MouseEvent):void

{

        gotoAndStop(102);

        t.stop();

}

stop();

This topic has been closed for replies.

2 replies

Inspiring
April 22, 2013

For details of working with Sound see here:

For loading external Sounds use sth like this:

var snd:Sound = new Sound(new URLRequest(moveSound[0]));

snd.play();

As kglad pointed already out: use only small/streamable fileformats (mp3) for this, otherwise you will run into problems.

If you absolutely must use ogg, you will have to look into additional libraries like these

kglad
Community Expert
Community Expert
April 21, 2013

i don't see any place where you're trying to use anything in moveSound.

in addition, you can only load mp3, not wav or oga files.  (and, while those could be class strings, that seems unlikely.)