#include "Command.as"
#include "Sequence.as"
/*
A Sequence object internally creates command objects which will be executed
at specified 'tickCount's.
If there are multiple commands at the same tickCount, they are chained so each
command will be executed by the callback of the previous command.
*/
//user-function example, used by a movieclip 'window' and a dynamic textfield 'window.msg_txt'.
Object.prototype.linearTween = function (propName, valStep, endVal) {
var callback = Command.callback;
var o = this;
var isDone = (valStep > 0) ? function() {return o[propName] > endVal}
: function() {return o[propName] < endVal};
this.id = setInterval(function () {
o[propName] += valStep;
if (isDone()) {
clearInterval(o.id);
o[propName] = endVal;
callback();
}
}, 50);
};
ASSetPropFlags(Object.prototype, null, 1);
window._xscale = 0;
window._yscale = 10;
//create a Sequence object. Commands on the same tickCount get chained,
//so they will be executed one after another
seq1 = new Sequence(
[ 0, function() {msg_txt.text = ""; Command.callback();}],
[ 0, function() {btn1.enabled = btn2.enabled = false; Command.callback();}],
[ 0, window, "linearTween", "_xscale", 20, 100],
[ 0, window, "linearTween", "_yscale", 20, 100],
[ 5, function() {window.msg_txt.text = "Hello"; Command.callback();}],
[15, function() {window.msg_txt.text = "Bye"; Command.callback();}],
[15, window.msg_txt, "linearTween", "_alpha", -12, 0],
[15, function() {window.msg_txt.text = ""; window.msg_txt._alpha = 100; Command.callback();}],
[20, window, "linearTween", "_yscale", -20, 10],
[20, window, "linearTween", "_xscale", -20, 0],
[20, function() {btn1.enabled = btn2.enabled = true; Command.callback();}],
["onSequenceComplete", function() {msg_txt.text = "Done";}]
);
seq1.setIntervalTime(50);
btn1.onRelease = function () {
seq1.execute();
};
The code for btn2
//Nested sequences example.
seq2 = new Sequence(
[0, seq1, "execute"],
[0, seq1, "execute"],
["onSequenceComplete", function() {msg_txt.text = "All Done";}]
);
btn2.onRelease = function () {
seq2.execute();
};