Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Sound Button, ActionScript 3.0

New Here ,
Jan 18, 2012 Jan 18, 2012

Hi, I am a newbie to ActionScript but I do have an understanding of scripting. I have worked in designing games on a few game engines and now I am looking into ActionScript 3.0

I created a script by getting some details here and there on the web and this is what Ive come up with,

var loadSnd:URLRequest = new URLRequest("Sound.wav");

var thisSnd:Sound = new Sound();

thisSnd.load(loadSnd);

Sound_1.addEventListener(MouseEvent.CLICK, playF);

function playF(event:MouseEvent);void{

          thisSnd:play(); //Line 8

}

Output:

Scene 1, Layer 'Actions', Frame 1, Line 81084: Syntax error: expecting rightbrace before semicolon.

I dont think this is a difficult error to fix but it is an issue for me at the moment.

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 19, 2012 Jan 19, 2012

you can't load a wav.  use an mp3.

Translate
Community Expert ,
Jan 18, 2012 Jan 18, 2012

use:

var loadSnd:URLRequest = new URLRequest("Sound.wav");

var thisSnd:Sound = new Sound();

thisSnd.load(loadSnd);

Sound_1.addEventListener(MouseEvent.CLICK, playF);

function playF(event:MouseEvent);void{

          thisSnd.play(); //Line 8

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2012 Jan 19, 2012
Scene 1, Layer 'Actions', Frame 1, Line 81084: Syntax error: expecting colon before dot.
Scene 1, Layer 'Actions', Frame 1, Line 91084: Syntax error: expecting identifier before rightbrace.

The output returned those two statements up there.

My piece of code isn't exactly efficent. I imagine there are errors that are difficult to spot. Perhaps writing a new script is a better idea?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2012 Jan 19, 2012

another error in your code:

kglad wrote:

use:

var loadSnd:URLRequest = new URLRequest("Sound.wav");

var thisSnd:Sound = new Sound();

thisSnd.load(loadSnd);

Sound_1.addEventListener(MouseEvent.CLICK, playF);

function playF(event:MouseEvent):void{

          thisSnd.play(); //Line 8

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2012 Jan 19, 2012

That fixed the Button.

Now Actionscript 3.0 is giving me the following error.

ArgumentError: Error #2068: Invalid sound.

          at flash.media::Sound/play()

          at Project_fla::MainTimeline/playF()[Project_fla.MainTimeline::frame1:8]

It looks like the sound I created doesn't exist.

Is there a certain folder I must place my sound Instance in?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2012 Jan 19, 2012

you can't load a wav.  use an mp3.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2012 Jan 19, 2012

Oh, Ok thanks for the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2012 Jan 19, 2012
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines