Copy link to clipboard
Copied
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?
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();
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
But that name should I assign it would be in the Class? Or Base Class?
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now