Q:

Get to know the layer order in the flash timeline via as3 code

Is there any method with which I can get to know which of the two movieclips I'm using is lying above or below in the timeline 'layer' arrangement in flash.
what I'm asking is if have two movieclips 'a' and 'b'. One in layer 10 of timeline of flash professional and 'b' on layer 1. Will be able to change the index order using pure as3 code to visually keep the movieclip on the 10th layer on top of the movieclip on 1st layer??
Thank you.
Vishnu

A:

[[Edit]]
The attached method will not work if both target objects are leaf nodes in a shared parent.

The timeline children are always under whatever actionscript generated children are associated to the timeline class.
e.g.
If you have timeline X, which extends ClassA, and in Class A, you add children E, F, G, but timeline X contains layers B, C, D, each with a single symbol in each layer, with layer B at the bottom of the timeline, the following would be observed:
child 5: G
child 4: F
child 3: E
child 2: D
child 1: C
child 0: B

To expand on a felipemaia's answer, I've devised the following method to determine which movie clip lies absolutely above the other.  This has not been thoroughly tested, but should operate as a baseline for your development.
function selectAbove(obj1:DisplayObject, obj2:DisplayObject):DisplayObject
{

    var obj1_parentCount:int = parentCount(obj1);
    var obj2_parentCount:int = parentCount(obj2);

    var target:DisplayObject;
    var other:DisplayObject;

    if (obj1_parentCount > obj2_parentCount)
    {
        target = obj1;
        other = obj2;
    }
    else
    {
        target = obj2;
        other = obj1;
    }

    var container:DisplayObjectContainer =
        (target is DisplayObjectContainer) ? target as DisplayObjectContainer : target.parent ;

    var container_last:DisplayObjectContainer;

    var sharedParent:DisplayObjectContainer;

    while(container)
    {
        if(container.contains(other))
        {
            sharedParent = container;
            break;
        }

        container_last = container;
        container = container.parent;
    }

    if(!sharedParent)
    {
        throw new Error("An object does not maintain its parent in the display heirarchy!");
    }

    var ret:DisplayObject;

    if(container == other)
    {
        ret = target;
    }

    return container != other ?
        container.getChildIndex(container_last) < container.getChildIndex(other) ?
            other :
            target
        :
        target
    ;
}

function parentCount(obj:DisplayObject):int
{
    var ret:int = 0;

    while(obj)
    {
        ret++;
        obj = obj.parent;
    }

    return ret;
}

This method will work for nested display hierarchies.  I have not tested this 100%, but initial cases completed as expected.
Best of luck!

