Log in

View Full Version : Array of MC to call a sound clip when pressed.



tivaelydoc
01-01-2009, 11:13 PM
I've got sound clips for words. For example, lets say the word is doorknob, then I have a sound clip in the library named doorknob and it's exported for actionscript with the same identifier name.

From there, I have a list of all the words. So, somehow could I write up a array which takes the words, puts each one on the stage (1 per row so it stacks vertically) as a MC that when clicked plays the sound clip in the library?

Because of the large amount of words, I would have to have some sort of scroll bar, but I don't know how I would do that either.



So, I got part of it figured out:


var wordlist:Array = Array("dog", "bowl", "fighting", "chair", "venezuela");
thing_array.sort();

Pretty much this would store all my words and sort em I guess.

Then from there, I would use a master button (Button) to attach onto the stage. As well, it would have to be stacked vertically:


for (i=1; i<wordlist.length; i++) {
words = attachMovie("wordbut", "wordbut"+i, getNextHighestDepth());
words._x = 8;
words._y = words._width*i-words._width+8;
words.num = i;
words.onPress = function() {
// this is the part I don't know
};

}


Somehow, I would have to put the text on each button. So that, there would a stack of buttons and on top of each button would be the word in the array. If brackets equal a button, then this is what I want it to look like:
[ dog ]
[ bowl ]
[ fighting ]
[ chair ]
[ venezuala ]

Then from there, when the MC is pressed, it finds the word (let's say dog) and finds the mp3 in the library and plays it every time it's clicked.

How would I put the text on each button? Figured that out.
How would I make it play the mp3 when clicked? Figured that out.
How would I set it up to scroll?
Is there someway to make a variable so that the width of the button of the MC is equal to the length of the word?

Here is the FLA:

http://tivaelydoc.110mb.com/soundbut.fla

Updated the FLA!


The only thing I need to figure out is how to scroll and maybe how to figure out how to set the width of the button to be the same size as the length of the text.

Here is the new AS:


var wordlist:Array = Array("dog", "bowl", "fighting", "chair", "venezuela");
wordlist.sortOn(name);
var s:Sound = new Sound(this);
for (i=0; i<wordlist.length; i++) {
var words:MovieClip = attachMovie("but", "wordbut"+i, this.getNextHighestDepth());
words._x = 80;
words._y = ((words._height+10)*i)+30;
words.num = i;
words.inner_txt.text = wordlist[i];
words.onPress = function() {
s.attachSound(wordlist[this.num]);
s.start();
};

}