Skip to main content
Inspiring
February 23, 2015
Answered

Function Sound

  • February 23, 2015
  • 1 reply
  • 553 views

I imported a sound file, but do not know how to use the functions. I will give an example of what I'm trying to do ...

The name of the imported file is "sound" and I want that when an object touches the other is called the sound.

if(ball.hitTestObject(wall)) {

  // Sound

  gotoAndPlay(2);

}

The where is "// sound" I do not know what use to call the sound, can anyone help me?

This topic has been closed for replies.
Correct answer moccamaximum

You have to export your sound for Actionscript (righclickon it in th e Library, that should give you the option.

Then under "Export for Actionscript"  name it "MySound" (stay away from naming your objects just "sound" or "Sound" since it can interfere with AS3 conventions)

Then add this to your code

var mySound:MySound = new MySound();

  1. if(ball.hitTestObject(wall)) { 
  2.   // Sound 
  3.   gotoAndPlay(2);
  4. mySound.play();
  5. }

1 reply

moccamaximumCorrect answer
Inspiring
February 23, 2015

You have to export your sound for Actionscript (righclickon it in th e Library, that should give you the option.

Then under "Export for Actionscript"  name it "MySound" (stay away from naming your objects just "sound" or "Sound" since it can interfere with AS3 conventions)

Then add this to your code

var mySound:MySound = new MySound();

  1. if(ball.hitTestObject(wall)) { 
  2.   // Sound 
  3.   gotoAndPlay(2);
  4. mySound.play();
  5. }
vvvverTAuthor
Inspiring
February 23, 2015

But that name should I assign it would be in the Class? Or Base Class?

Inspiring
February 24, 2015

Class: MySound

Base Class: flash.media.Sound


Remember to differentiate between your class and the instance (object) you are creating from your class by naming your class MySound and your object mySound