命名空间内部的定义事件存在冲突

时间:2015-07-31 17:00:30

标签: actionscript-3 flash

我是as3的新手。我收到这个错误:

  

内部命名空间中的定义事件存在冲突。

我使用相同的编码但不同的场景。我改变了第二个场景。

var mysound:bila =new bila()

这是我第一个场景的代码,仅在第一个场景中成功:

var isItPlaying:Boolean = true;
var lastposition:Number = 0;
var mysound:izhar = new izhar();
var soundchannel:SoundChannel = new SoundChannel();
soundchannel = mysound.play(0,0);// playing sound in the channel
soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete1);

function onPlaybackComplete1(event:Event):void
{
    lastposition = 0;
    soundchannel.stop();
    btn.btn_pause.visible = false;
    trace("finished");
    isItPlaying=false;
}
/************end of part 1********/

btn.addEventListener(MouseEvent.CLICK, playsound);*

function playsound(event:MouseEvent):void*
{
    if (! isItPlaying)
    {
        soundchannel = mysound.play(lastposition,0);
        btn.btn_pause.visible = true;
        isItPlaying = true;
    }
    else
    {
        lastposition = soundchannel.position;
        soundchannel.stop();
        btn.btn_pause.visible = false;
        /*trace(lastposition.toFixed(0), mysound.length.toFixed(0));*/
        isItPlaying = false;
    }

    soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);*

    function onPlaybackComplete(event:Event):void
    {
        lastposition = 0;
        soundchannel.stop();
        btn.btn_pause.visible = false;
        trace("finished");
        isItPlaying=false;
    }
}

1 个答案:

答案 0 :(得分:2)

冲突是因为您在同一范围内声明了两个具有相同名称的变量。

您将event变量声明为playsound函数中的参数。然后你有一个嵌套函数onPlaybackComplete,声明一个具有相同名称的参数。

要解决此问题,请将其中一个参数重命名为其他参数,或将onPlaybackComplete函数移到playsound函数之外,以使其具有自己的范围。

我更喜欢第二个选项,除非您因某些特定原因需要嵌套该功能。