Reorder z order of layer

Step1. Get layer
var layer = inst.layer;
or
var layer = (typeof layerparam == "number")?
            this.runtime.getLayerByNumber(layerparam):
            this.runtime.getLayerByName(layerparam);


Step2. Sort the list layer.instances
layer.instances(SORTFN);
for example
function sortInstanceByZIndex(a, b)
{

    return a.zindex - b.zindex;
}

Step3. reassign zindex of instances in this layer.
layer.zindices_stale = true;


Reference

Get timeline instance

instanceProto._timeline_get = function ()
{
    if (this.timeline != null)
        return this.timeline;

    assert2(cr.plugins_.Rex_TimeLine, "Scenario: Can not find timeline oject.");
    var plugins = this.runtime.types;
    var name, inst;
    for (name in plugins)
    {
        inst = plugins[name].instances[0];
        if (inst instanceof cr.plugins_.Rex_TimeLine.prototype.Instance)
        {
            this.timeline = inst;
            return this.timeline;
        }
    }
    assert2(this.timeline, "Scenario: Can not find timeline oject.");
    return null; 

};

Reference

Create instance

instanceProto.CreateInst = function (objtype,x,y,_layer)
{

    var layer = (typeof _layer == "number")?
                this.runtime.getLayerByNumber(_layer):
                (typeof _layer == "string")?

                this.runtime.getLayerByName(_layer):
                _layer;
 

    // call system action: Create instance
    cr.system_object.prototype.acts.CreateObject.call(
        this.runtime.system,
        objtype,
        layer,
        x,
        y
    );

   
    return objtype.getFirstPicked();  // return the created instance
};


Reference