Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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 typeError:Error#1006:setChildIndex不是函数_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 typeError:Error#1006:setChildIndex不是函数

Actionscript 3 typeError:Error#1006:setChildIndex不是函数,actionscript-3,flash,Actionscript 3,Flash,你知道是什么导致了这个错误吗? TypeError:Error#1006:setChildIndex不是函数。 at Function/()[iVision\u Game\u fla.main时间线::frame83:151] 这是我认为错误发生的地方 function dragObject(indx1:int,indx2:int):Function { return function(event:MouseEvent){ var item:MovieClip=MovieClip(event.

你知道是什么导致了这个错误吗? TypeError:Error#1006:setChildIndex不是函数。 at Function/()[iVision\u Game\u fla.main时间线::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);

我认为范围是这里的问题。如果项的父项未更改,则可以使用item.parent.setChildIndex(item,topPos)

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

更新:

为了进一步调试,在setChildIndex(151)的行上放置一个断点。(添加断点:单击行号左侧。它将添加一个小红色圆圈。当代码在调试模式下点击该断点时,它将停止。)

然后转到调试->调试电影->调试

当它停止时,打开调试面板:窗口->调试面板->变量,窗口->调试面板->调用堆栈

在变量面板中,您应该看到范围中的所有当前变量。您要查找的是调用setChildIndex的对象存在问题。在本例中,是项的父项。你可以深入了解这是什么。它应该是一个DisplayObjectContainer(MovieClip、Sprite等)。项来自event,所以我还要检查event.currentTarget。您基本上是在尝试确认在该断点处,项存在,它有一个父项,并且它的父项是一个DisplayObjectController。如果其中一个不是真的,你可以从这里追溯为什么不是这样

TypeError:Error#1006:setChildIndex不是函数

您已经创建了匿名函数,如果您想要捕获此,您可以执行以下构造:

var selfRef:MyClass = this;
现在,MouseEvent的处理程序将显示:

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

谢谢你的快速回复,但我真的不明白,因为我是as3新手…我尝试过你的建议,但当我单击该项目时,它消失了。它的功能正常,但我担心它会对我的应用程序产生什么影响。它与我们开始的相同。是的,错误发生在这一行“this.setChildIndex(item,topPos)”上,它显示了这一点“TypeError:Error#1006:setChildIndex不是函数。在函数/()[iVision\u Game\u fla.main时间线::frame83:151]”