Official function to create an instance

Official function to create an instance, see system.js, line 1284.

SysActs.prototype.CreateObject = function (obj, layer, x, y)
{
    if (!layer || !obj)
        return;

    var inst = this.runtime.createInstance(obj, layer, x, y);
 
    if (!inst)
        return;
 
    this.runtime.isInOnDestroy++;
 
    var i, len, s;
    this.runtime.trigger(Object.getPrototypeOf(obj.plugin).cnds.OnCreated, inst);
 
    if (inst.is_contained)
    {
        for (i = 0, len = inst.siblings.length; i < len; i++)
        {
            s = inst.siblings[i];
            this.runtime.trigger(Object.getPrototypeOf(s.type.plugin).cnds.OnCreated, s);
        }
    }
 
    this.runtime.isInOnDestroy--;

    // Pick just this instance
    var sol = obj.getCurrentSol();
    sol.select_all = false;
    sol.instances.length = 1;
    sol.instances[0] = inst;
 
    // Siblings aren't in instance lists yet, pick them manually
    if (inst.is_contained)
    {
        for (i = 0, len = inst.siblings.length; i < len; i++)
        {
            s = inst.siblings[i];
            sol = s.type.getCurrentSol();
            sol.select_all = false;
            sol.instances.length = 1;
            sol.instances[0] = s;
        }
    }
};

Procedure of plugins and event sheet in each tick

  1. pretick() in plugins
  2. tick() in behaviors
  3. posttick() in behaviors
  4. tick() in plugins
  5. "condition: every tick" in event sheet
  6. tick2() in behaviors
  7. tick2() in plugins
  8. draw() in engine 

Reference: preview.js, line 2416, function "logic".

Get behavior instance

function GetThisBehavior(inst)
{
    var i, len;
    for (i = 0, len = inst.behavior_insts.length; i < len; i++)
    {
        if (inst.behavior_insts[i] instanceof behaviorProto.Instance)
            return inst.behavior_insts[i];
    }
        return null;
};

See the official DragnDrop behavior.
"behaviorProto" could be changed to specific behavior.