Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3动态访问声音通道_Actionscript 3_Flash_Air - Fatal编程技术网

Actionscript 3 AS3动态访问声音通道

Actionscript 3 AS3动态访问声音通道,actionscript-3,flash,air,Actionscript 3,Flash,Air,我有一个flash项目,同时激活了许多声音通道。我需要一个小函数来播放一个并循环它,并且声音通道的名称将作为参数传递。这就是功能: function playBGMusic(channel:String):void { SoundChannel(channel) = bgSound1.play(); SoundChannel(channel).addEventListener(Event.SOUND_COMPLETE, loopBGMusic); } playBGMusic(

我有一个flash项目,同时激活了许多声音通道。我需要一个小函数来播放一个并循环它,并且声音通道的名称将作为参数传递。这就是功能:

function playBGMusic(channel:String):void
{
    SoundChannel(channel) = bgSound1.play(); 
    SoundChannel(channel).addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
}

playBGMusic("bgChannel1");
这不起作用,flash给了我以下错误:

1105:赋值的目标必须是参考值

我试图简化函数,只在侦听器中使用静态字符串

function playBGMusic():void
{
    bgChannel1 = bgSound1.play(); 
    SoundChannel("bgChannel1").addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
}

playBGMusic();
这次它编译了,但它给了我一个错误:

错误#1034:类型强制失败:无法将“bgChannel1”转换为 flash.media.SoundChannel

如何从字符串访问声音通道


Thaks.

您需要在
的上下文中访问它:

SoundChannel(此[频道])
SoundChannel(此[“bgChannel1”)