【问题标题】:typeError: Error #1006: setChildIndex is not a functiontypeError:错误 #1006:setChildIndex 不是函数
【发布时间】:2014-04-17 13:29:11
【问题描述】:

您知道导致此错误的原因吗? TypeError:错误 #1006:setChildIndex 不是函数。 在函数/()[iVision_Game_fla.MainTimeline::frame83:151]

这就是我认为错误发生的地方......

function dragObject(indx1:int,indx2:int):Function { 
return function(event:MouseEvent){
var item:MovieClip=MovieClip(event.currentTarget); 
item.startDrag(); 
var topPos:uint=this.numChildren-1; 
var itemSound:Sound = new Sound();
itemSound.load(new URLRequest("sounds/"+dirArray[indx1])+indx2+".mp3"));
if(!activeSound)
{
    itemSound.play();
    activeSound=true;
}
this.setChildIndex(item, topPos);
}

}

//在另一个函数上调用它

var functionOnDrag:Function = dragObject(indexc[count-1],index[count2]);
pb[i].addEventListener(MouseEvent.MOUSE_DOWN,functionOnDrag);

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案1】:

    我认为范围是这里的问题。如果 item 的 parent 没有改变,你可以使用 item.parent.setChildIndex(item, topPos)

    另外,在此之前,topPos:uint = item.parent.numChildren -1;

    更新:

    要进一步调试,请在 setChildIndex (151) 的行上放置一个断点。 (添加断点:点击行号左侧。会添加一个小红圈。当代码在调试模式下点击它会停止。)

    然后去调试 -> 调试电影 -> 调试

    当它停止时,打开调试面板:Window->Debug Panels->Variables, Window->Debug Panels->Callstack

    在变量面板中,您应该可以看到范围内的所有当前变量。您正在寻找的是调用 setChildIndex 的对象的问题。在这种情况下,项目的父项。您可以深入了解它是什么。它应该是一个 DisplayObjectContainer(MovieClip、Sprite 等...)。项目来自事件,所以我也会检查 event.currentTarget。您基本上是在尝试确认在该断点处是否存在项目,它有一个父级,并且它的父级是一个 DisplayObjectController。如果其中之一不正确,您可以从这里向后追溯为什么不是这样。

    【讨论】:

    • 感谢您的快速回复,但我真的不明白,因为我是 as3 的新手...我已经尝试过您的建议,但是当我单击该项目时它消失了
    • 它正在运行,但我担心它会对我的应用程序产生什么影响
    • 和我们开始的一样
    • 是的,错误发生在“this.setChildIndex(item,topPos)”这一行
    • 它显示这个“TypeError: Error #1006: setChildIndex is not a function. at Function/()[iVision_Game_fla.MainTimeline::frame83:151]”
    【解决方案2】:

    TypeError:错误 #1006:setChildIndex 不是函数

    你已经创建了匿名函数,如果你想捕获this,你可以这样构造:

    var selfRef:MyClass = this;
    

    现在您的 MouseEvent 处理程序将如下所示:

    function dragObject(indx1:int, indx2:int):Function {
        return function (event:MouseEvent) {
            //Your code
            selfRef.setChildIndex(item, topPos);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 2014-11-18
      相关资源
      最近更新 更多