Extending upon the chain of events created in the previous section, this recipe shows us how to clear a chain of events using Chain.clearChain()
.
Get ready to call this function by adding a widget to which our clearing function can be bound.
<input type="button" id="mycancel" value="Clear Chain"/>
Calling the clearChain()
method of the my_chain
object, which is an instantiation of MooTools Chain, removes the current call stack completely.
$('mycancel').addEvent('click',function() { alert('Clearing chain:'+my_chain.$chain.length+' actions'); my_chain.clearChain(); alert('Done! Chain has:'+my_chain.$chain.length+' actions'); });
Each call to my_chain.chain(advance_one_number)
added another array argument to the internally maintained $chain
array. This array is a property of the chain object instantiation. Calling my_chain.clearChain()
zeroes out the $chain
property of my_chain
.