Results 1 to 1 of 1

Thread: Array of MC to call a sound clip when pressed.

  1. #1
    Join Date
    Jul 2007
    Posts
    40
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Array of MC to call a sound clip when pressed.

    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:

    PHP Code:
    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:

    PHP Code:
    for (i=1i<wordlist.lengthi++) {
        
    words attachMovie("wordbut""wordbut"+igetNextHighestDepth());
        
    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:
    PHP Code:
    var wordlist:Array = Array("dog""bowl""fighting""chair""venezuela");
    wordlist.sortOn(name);
    var 
    s:Sound = new Sound(this);
    for (
    i=0i<wordlist.lengthi++) {
        var 
    words:MovieClip attachMovie("but""wordbut"+ithis.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();
        };


    Last edited by tivaelydoc; 01-02-2009 at 05:28 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •