【问题标题】:A conflict exists with definition event in namespace internal与命名空间内部的定义事件存在冲突
【发布时间】:2015-10-23 10:41:30
【问题描述】:

我是 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;
    }
}

【问题讨论】:

  • 您是否在代码顶部导入任何包?

标签: actionscript-3 flash


【解决方案1】:

冲突是因为你在同一个作用域中声明了两个同名的变量。

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

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

我更喜欢第二个选项,除非您出于某种特定原因需要嵌套该函数。

【讨论】:

    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    相关资源
    最近更新 更多