home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sears Catalog 2006 Spring/Summer (French Canadian)
/
SearsCanada-AutomneEte2006-FrenchVersion-WinMac.bin
/
fr
/
calendar
/
lmc_tween_as1.as
< prev
next >
Wrap
Text File
|
2005-07-27
|
17KB
|
658 lines
/*
Tweening prototypes for AS 1.0
version 1.1.7
Ladislav Zigo,lacoz@web.de
*/
#include "easing_equations.as"
//
var Mp = MovieClip.prototype;
//
AsBroadcaster.initialize(Mp);
Mp.$addListener = Mp.addListener;
ASSetPropFlags(Mp, "$addListener", 1, 0);
Mp.addListener = function(){
AsBroadcaster.initialize(this);
this.$addListener.apply(this,arguments);
}
//
function tweenManager() {
this.playing = false
this.autoStop = false;
this.broadcastEvents = false;
this.autoOverwrite = true;
this.tweenList = new Array()
this.ints = new Array();
this.lockedTweens = new Object();
this.now = 0;
this.isPaused = false;
this.pausedTime = 0;
}
var tp = tweenManager.prototype;
tp.setupdateInterval = function(time){
if (this.playing){
this.deinit()
this.updateTime = time
this.init()
}else{
this.updateTime = time
}
}
tp.getupdateInterval = function(){
return this.updateTime;
}
tp.addProperty("updateInterval",tp.getupdateInterval, tp.setupdateInterval);
//
tp.init = function(){
var tm = this;
if(tm.updateTime > 0){
tm.updateIntId = setInterval(tm,"update",tm.updateTime);
}else{
if(tm.tweenHolder._name == undefined){
tm.tweenHolder = _root.createEmptyMovieClip("_th_",6789);
}
//tweenHolder.onEnterFrame = update
tm.tweenHolder.onEnterFrame = function(){
tm.update.call(tm);
}
}
tm.playing = true;
tm.now = getTimer();
}
//
tp.deinit = function(){
this.playing = false;
clearInterval(this.updateIntId);
delete this.tweenHolder.onEnterFrame;
}
//-------------------------- private methods
tp.update = function() {
var i, t, j;
i = this.tweenList.length;
if(this.broadcastEvents){
// list of updated mcs
var ut = {};
// list of ending mcs
var et = {};
}
while (i--) {
t = this.tweenList[i];
if (t.ts+t.d>this.now) {
// compute value using equation function
if (t.ctm == undefined) {
// compute primitive value
t.mc[t.pp] = t.ef(this.now-t.ts, t.ps, t.ch, t.d, t.e1, t.e2);
} else {
// compute color transform matrix
// stm is starting transform matrix,
// ctm is change in start & destination matrix
// ttm is computed (temporary) transform matrix
// c is color object
var ttm = {};
for (j in t.ctm) {
ttm[j] = t.ef(this.now-t.ts, t.stm[j], t.ctm[j], t.d, t.e1, t.e2);
}
t.c.setTransform(ttm);
}
if(this.broadcastEvents && ut[targetpath(t.mc)] == undefined){
ut[targetpath(t.mc)] = t.mc;
}
if(t.cb.updfunc != undefined){
t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs);
}
} else {
// end , set up the property to end value;
if (t.ctm == undefined) {
t.mc[t.pp] = t.ps+t.ch;
} else {
var ttm = {};
for (j in t.ctm) {
ttm[j] = t.stm[j]+t.ctm[j];
}
t.c.setTransform(ttm);
}
if(this.broadcastEvents){
if(ut[targetpath(t.mc)] == undefined){
ut[targetpath(t.mc)] = t.mc;
}
if(et[targetpath(t.mc)] == undefined){
et[targetpath(t.mc)] = t.mc;
}
}
if(t.cb.updfunc != undefined){
t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs);
}
if (endt == undefined){
var endt = new Array();
}
endt.push(i);
}
}
for (j in ut){
ut[j].broadcastMessage('onTweenUpdate');
}
if(endt != undefined){
this.endTweens(endt);
}
for (j in et){
et[j].broadcastMessage('onTweenEnd');
}
this.now = getTimer();
// update timer
if (this.updateTime > 0){
updateAfterEvent();
}
};
tp.endTweens = function(tid_arr){
var cb_arr, tl, i, cb, j
cb_arr = []
// splice tweens from tweenlist
tl = tid_arr.length
with(this){
for (i = 0; i<tl; i++){
cb = tweenList[tid_arr[i]].cb
if(cb != undefined){
var exec = true;
//do not add callbacks that are in cb_arr
for(j in cb_arr){
if (cb_arr[j] == cb){
exec = false;
break;
}
}
//
if(exec){
cb_arr.push(cb)
}
}
tweenList.splice(tid_arr[i],1);
}
// execute callbacks
for (i = 0; i<cb_arr.length;i++){
cb_arr[i].func.apply(cb_arr[i].scope,cb_arr[i].args)
}
//
// /*1.1.6*/
if(tweenList.length==0){
// last tween removed, erase onenterframe function
deinit();
}
}
}
// ------------- public methods
tp.addTween = function(mc,props,pEnd,sec,eqFunc,callback,extra1,extra2){
var i, pp, addnew, j, t;
with(this){
//
if(!playing){
init();
}
for(i in props){
pp = props[i];
addnew = true;
//
if(pp.substr(0,4)!="_ct_"){
// there is no color transform prefix, use primitive value tween
//
if(autoOverwrite){
// find coliding tween and overwrite it
for (j in tweenList){
t = tweenList[j];
if(t.mc == mc && t.pp == pp){
//
t.ps = mc[pp];
t.ch = pEnd[i] - mc[pp];
t.ts = now;
t.d = sec*1000;
t.ef = eqFunc;
t.cb = callback;
t.e1 = extra1;
t.e2 = extra2;
addnew = false;
break;
}
}
}
if(addnew){
// not found add new
tweenList.unshift({
mc: mc,
pp: pp,
ps: mc[pp],
ch: pEnd[i] - mc[pp],
ts: now,
d: sec * 1000,
ef: eqFunc,
cb: callback,
e1: extra1,
e2: extra2});
}
}else{
// color trasform prefix found
// compute change matrix
var c = new Color(mc);
var stm = c.getTransform();
// compute difference between starting and desionation matrix
var ctm = {}
for(j in pEnd[i]){
// if is in destination matrix
if(pEnd[i][j] != stm[j] && pEnd[i][j] != undefined ){
ctm[j] = pEnd[i][j] - stm[j];
}
}
if(autoOverwrite){
// find coliding tween and overwrite it
for (j in tweenList){
t = tweenList[j];
if(t.mc == mc && t.ctm != undefined){
//
t.c = c
t.stm = stm
t.ctm = ctm,
t.ts = now;
t.d = sec*1000;
t.ef = eqFunc;
t.cb = callback;
t.e1 = extra1;
t.e2 = extra2;
addnew = false; break;
}
}
}
if(addnew){
tweenList.unshift({
mc: mc, //reference to movieclip
c: c, //reference to movieclip color
stm: stm, //starting transform matrix
ctm: ctm,
ts: now,
d: sec * 1000,
ef: eqFunc,
cb: callback,
e1: extra1,
e2: extra2
})
}
}
} // end for
if(broadcastEvents){
mc.broadcastMessage('onTweenStart');
}
if(callback.startfunc != undefined){
callback.startfunc.apply(callback.startscope,callback.startargs)
}
}// end with
}
tp.addTweenWithDelay = function(delay,mc,props,pEnd,sec,eqFunc,callback,extra1,extra2){
with(this){
var il = ints.length;
var intid = setInterval(function(obj){
obj.addTween(mc, props, pEnd, sec, eqFunc, callback, extra1, extra2);
clearInterval(obj.ints[il].intid);
obj.ints[il] = undefined;
},delay*1000,this);
//
ints[il] = {mc: mc, props: props, pend:pEnd, intid:intid, st: this.now, delay:delay*1000, args: arguments.slice(1)}
}
}
//
tp.removeTween = function(mc,props){
with (this){
var all, i, j
all = false;
if(props == undefined){
// props are undefined, remove all tweens
all = true;
}
i = tweenList.length;
while (i--){
if(tweenList[i].mc == mc){
if(all){
tweenList.splice(i,1);
}else{
for(j in props){
if(tweenList[i].pp == props[j] && tweenList[i].mc == mc){
tweenList.splice(i,1);
// (because allows add same properties for same mc,
// all tweens must be checked)
} else if (props[j] == "_ct_" && tweenList[i].ctm != undefined && tweenList[i].mc == mc){
// removing of colorTransform tweens
tweenList.splice(i,1);
}
}
}
}
}
i = ints.length;
while(i-- && ints[i].mc == mc){
if(all){
// REMOVE ALL
clearInterval(ints[i].intid)
ints[i] = undefined
} else {
// REMOVE PROPERTIES
for(j