开发者

How to Create Sound Object Dynamically

How to create sound object dynamically in one movieClip.

Example

开发者_C百科for(i=1;i<5;i++){var sound + i = new Sound();}


You can try putting all the sounds from your loop inside an Array:

var soundArray:Array = [];
for (var i:uint = 0; i < 5; i++) {
    var sound:Sound = new Sound(); 
    // don't forget to set the path of the file you want to play

    soundArray.push(sound);
}

To play the the sound, all you need to do is take note of the index:

Sound(soundArray[0]).play();

Hope this helps.

irot


you need a MovieClip to store your sounds into then:

var mc:MovieClip = new MovieClip();
for( var i:int = 0; i < 5; i++ )
{
    mc[ 'sound_' + i ] = new Sound(); 
}

to access a sound, you can then call:

mc[ 'sound_0' ].play();

if you're already in the scope of a MovieClip, ignore the mc creation and replace 'mc' with 'this' in the loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜