Search code examples
flashactionscript-33daway3d

How to get the top level child in away3D?


i have a small question concerning away3D. I have some cubes with the exact same dimensions that are positioned in the same place. When i click on the stack of cubes, i want to register a click on the cube i added last. Instead of doing this, the click is registered on the cube i added first.

I have found a way to alter the cubes position in the container and have tried putting the element at the end (code below) and start of the childrenArray, but nothing seems to work. I am kinda really stuck here, so if anyone knows how to get the top level element when clicking on the stack, i'd be happy to hear.

//We get the targetCube's childIndex.
for(var i:uint = 0; i < _3DContent.children.length; i++)
{
    if(_targetCube == _3DContent.children[i])
        break;
}

//Now we rearrange the array if the targetCube is different from
//the last cube in our list of children.
if(i != _3DContent.children.length-1)
{
    //We reposition the children.
    for(var j:uint = i; j < _3DContent.children.length-1; j++)
        _3DContent.children[j] = _3DContent.children[j+1];

    //Lastly, we push the child.
    _3DContent.children[_3DContent.children.length-1] = _targetCube;
}

Solution

  • I solved the problem by using a different renderer. When creating your view, you should pass this as a parameter, as shown below.

    _view = new View3D({renderer: Renderer.CORRECT_Z_ORDER});