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

Function Sound

Explorer ,
Feb 23, 2015 Feb 23, 2015

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?

TOPICS
ActionScript
498
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

Guru , Feb 23, 2015 Feb 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. }
Translate
Guru ,
Feb 23, 2015 Feb 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. }
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
Explorer ,
Feb 23, 2015 Feb 23, 2015

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

Sem título.png

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
Guru ,
Feb 23, 2015 Feb 23, 2015
LATEST

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

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