Destroy children objects when parent object destroyed

"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

No comments:

Post a Comment