0
votes

Do you know what causes this error? TypeError: Error #1006: setChildIndex is not a function. at Function/()[iVision_Game_fla.MainTimeline::frame83:151]

Here's where I think the error occurs...

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);
}

}

//calling it on another function

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

2 Answers

0
votes

I think scope is the problem here. If the item's parent isn't changing, you can use item.parent.setChildIndex(item, topPos)

Also, before that, topPos:uint = item.parent.numChildren -1;

Update:

To debug further, put a breakpoint on the line of setChildIndex (151). (adding a breakpoint: click to the left of the line number. it will add a little red circle. When code hits this in debug mode it will stop.)

enter image description here Then go to Debug -> Debug Movie -> Debug

When it stops, open the Debug Panels: Window->Debug Panels->Variables, Window->Debug Panels->Callstack

In the variable panel, you should see all the current variables in the scope. What you are looking for is an issue with the object that setChildIndex is being called on. In this case, the parent of item. You can drill down to see what that is. It should be a DisplayObjectContainer (MovieClip, Sprite, etc...). Item came from event, so i would check event.currentTarget as well. You are basically trying to confirm that at that breakpoint, item exists, it has a parent, and it's parent is a DisplayObjectController. If one of these isn't true, you can track backwards from here why this isn't the case.

0
votes

TypeError: Error #1006: setChildIndex is not a function

You have created anonymous function, if you want capture this, you could do such construction:

var selfRef:MyClass = this;

Now your handler for the MouseEvent will look:

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