"object.onDestroy"will be called while object is destroyed by "system action: destroy". But other object could not be destroyed under this function body -
instanceProto.onDestroy = function ()
{
this.runtime.DestroyInstance(other_object);
};
other_object will not be destroyed.
A solution to destroy other objects in this case is overwriting the "Destroy" function -
pluginProto.onCreate = function ()
{
pluginProto.acts.Destroy = function ()
{
this.runtime.DestroyInstance(this); // destroy this objet
this.runtime.DestroyInstance(other_object); // destroy other object
};
};
Reference - https://github.com/rexrainbow/C2Plugins/blob/master/plugins/rex_listCtrl/runtime.js#L18
- Endless loop -
Development notes of Construct 2's plugins
Override common ACEs of object
pluginProto.onCreate = function ()
{
// Override the 'set width' action
pluginProto.acts.SetWidth = function (w)
{
if (this.width !== w)
{
this.width = w;
this.text_changed = true; // also recalculate text wrapping
this.set_bbox_changed();
}
};
See the official text plugin.
The common ACEs could be found in commonace.js
{
// Override the 'set width' action
pluginProto.acts.SetWidth = function (w)
{
if (this.width !== w)
{
this.width = w;
this.text_changed = true; // also recalculate text wrapping
this.set_bbox_changed();
}
};
See the official text plugin.
The common ACEs could be found in commonace.js
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;
}
}
};
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;
}
}
};
Subscribe to:
Posts (Atom)