Forum Topic: Button that plays random sound FX?

(144 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

Bad-Atom

Reply To Post Reply & Quote

Posted at: 5/8/07 02:54 AM

Bad-Atom NEUTRAL LEVEL 19

Sign-Up: 12/28/03

Posts: 60

I'm trying to make a button that plays random sounds every time you click on it. I've looked here through all the AS tutorials but came up empty. Anyone here have any idea how to do this?


None

Dr34m3r

Reply To Post Reply & Quote

Posted at: 5/8/07 03:00 AM

Dr34m3r LIGHT LEVEL 20

Sign-Up: 03/07/06

Posts: 3,590

At 5/8/07 02:54 AM, Bad-Atom wrote: I'm trying to make a button that plays random sounds every time you click on it. I've looked here through all the AS tutorials but came up empty. Anyone here have any idea how to do this?

Say you have seven sounds. Have ONE MC that has seven frames. On those seven frames, put a stop(); action. Then, make a new MC on every frame, with each MC having a different sound. Then, have the button, and add the code that makes it on(release), _root.MCNAME.gotoAndStop(WHATEVER.THE.SCRIPT.
IS.FOR.RANDOM.FRAMES.BETWEEN.2-8)}

There's ur magic button.

Warshark is fucking awesome.
XBL Gamertag: ZeeAk

BBS Signature

None

Fion

Reply To Post Reply & Quote

Posted at: 5/8/07 07:30 AM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,373

Alternatively:

You could get all your sound files that you want to pick from in the library and right click and add select linkage. Then tick off the export for action script and name them beep1, beep2, beep3....beep7, respectively.

Then go to the main timeline and add the code:

bgSound1 = new Sound(this);
bgSound1.attachSound("beep1");
bgSound2 = new Sound(this);
bgSound2.attachSound("beep2");
bgSound3 = new Sound(this);
bgSound3.attachSound("beep3");
bgSound4 = new Sound(this);
bgSound4.attachSound("beep4");
bgSound5 = new Sound(this);
bgSound5.attachSound("beep5");
bgSound6 = new Sound(this);
bgSound6.attachSound("beep6");
bgSound7 = new Sound(this);
bgSound7.attachSound("beep7");

Then go to your button and add:

on (release) {
soundplay = Math.ceil(Math.random()*7)
_root["bgSound"+soundplay].start();
}

Walla!


None

Denvish

Reply To Post Reply & Quote

Posted at: 5/8/07 11:29 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 5/8/07 03:00 AM, Dr34m3r wrote:
At 5/8/07 02:54 AM, Bad-Atom wrote: I'm trying to make a button that plays random sounds every time you click on it. I've looked here through all the AS tutorials but came up empty. Anyone here have any idea how to do this?
Say you have seven sounds. Have ONE MC that has seven frames. On those seven frames, put a stop(); action. Then, make a new MC on every frame, with each MC having a different sound. Then, have the button, and add the code that makes it on(release), _root.MCNAME.gotoAndStop(WHATEVER.THE.SCRIPT.
IS.FOR.RANDOM.FRAMES.BETWEEN.2-8)}

There's ur magic button.

Why make a new MC for each frame? Just add the sound to the frame. Personally, I'd go for 8 frames, first frame empty with a stop(); action, then each of the other frames with a sound and a gotoAndStop(1); action. Put it on stage, give it the instance name 'SFX', then use

on(press){
_root.SFX.gotoAndStop(random(7)+2);
}

on the button

- - Flash - Music - Images - -

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 04:52 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!