| |||||||
Du magst keine Werbung? Wir auch nicht!
Einfach registrieren und die Werbung ist weg. Diese Nachricht sehen nur nicht registrierte Nutzer.
![]() |
| | LinkBack | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Neuer User Registriert seit: Jul 2006
Beiträge: 7
| Motion - Tween Class Robert Penner
Moin liebes Forum , ich habe mir eine für Euch wahrscheinlich relativ bekloppte Sache vorgenommen . Ein guter Freund von mir arbeitet mangels Kohle mit dem Flash Programm Swishmax und ich habe mir vorgenommen ihm eine Tween Funktion zu basteln . Als Vorlage habe ich mir die Motion un die Tween Class von Robert Penner aus dem Buch "Robert Penner’s Programming Macromedia Flash MX" genommen und versucht in eine Funktion zu packen . Dort fungiert die Motion Class als Oberklasse , mein Script bis dato sieht folgendermassen aus : Code: _global.Tween = function (obj, prop, func,begin,finish,duration, useSeconds) {
this.setObj (obj);
this.setProp (prop);
this.setFunc (func);
this.setBegin (begin);
this.setPosition (begin);
this.setFinish (finish);
this.setDuration (duration);
this.setUseSeconds (useSeconds);
this._listeners = [];
this.addListener (this);
this.start();
};
var MP = Tween.prototype;
initialize (MP);
MP.start = function () {
this.rewind();
MovieClip.addListener (this);
this.broadcastMessage ("onMotionStarted", this);
};
MP.stop = function () {
MovieClip.removeListener (this);
this.broadcastMessage ("onMotionStopped", this);
};
MP.resume = function () {
this.fixTime();
MovieClip.addListener (this);
this.broadcastMessage ("onMotionResumed", this);
};
MP.rewind = function (t) {
this.$time = (t == undefined) ? 1 : t;
this.fixTime();
};
MP.fforward = function () {
this.setTime (this.$duration);
this.fixTime();
};
MP.nextFrame = function () {
if (this.$useSeconds) {
this.setTime ((getTimer() - this.startTime) / 1000);
} else {
this.setTime (this.$time + 1);
}
};
MP.prevFrame = function () {
if (!this.$useSeconds) {this.setTime (this.$time - 1);}
};
MP.onEnterFrame = MP.nextFrame;
MP.toString = function () {
return "[Motion prop=" + this.prop + " t=" + this.time +" begin=" +this.begin+
" pos=" + this.position + " func=" + this.func+ " change=" + this.change + " duration " + this.duration + "]";
};
MP.setPosition = function (p) {
this.$prevPos = this.$pos;
this.$obj[this.$prop] = this.$pos = p;
this.broadcastMessage ("onMotionChanged", this, this.$pos);
};
MP.getPosition = function (t) {
//wird überschrieben mit der Funktion "getPosition" der Tween Class
}
MP.getPrevPos = function () {
return this.$prevPos;
};
MP.setTime = function (t) {
this.prevTime = this.$time;
if (t > this.duration) {
if (this.$looping) {
this.rewind (t - this.$duration);
this.broadcastMessage ("onMotionLooped", this);
} else {
this.stop();
this.broadcastMessage ("onMotionFinished", this);
}
} else if (t < 0) {
this.rewind();
} else {
this.$time = t;
}
this.update();
};
MP.getTime = function () {
return this.$time;
};
MP.setBegin = function (b) {
this.$begin = b;
};
MP.getBegin = function () {
return this.$begin;
};
MP.setDuration = function (d) {
this.$duration = (d == null || d <= 0) ? Infinity : d;
};
MP.getDuration = function () {
return this.$duration;
};
MP.setLooping = function (b) {
this.$looping = b;
};
MP.getLooping = function () {
return this.$looping;
};
MP.setObj = function (o) {
this.$obj = o;
};
MP.getObj = function () {
return this.$obj;
};
MP.setProp = function (p) {
this.$prop = p;
};
MP.getProp = function () {
return this.$prop;
};
MP.setUseSeconds = function (useSecs) {
this.$useSeconds = useSecs;
};
MP.getUseSeconds = function () {
return this.$useSeconds;
};
MP.fixTime = function () {
if (this.useSeconds){
this.startTime = getTimer() - this.$time*1000;}
};
MP.update = function () {
this.setPosition (this.getPosition (this.$time));
};
MP.setFunc = function (f) {
this.$func = f;
};
MP.getFunc = function () {
return this.$func;
};
MP.setChange = function (c) {
this.$change = c;
};
MP.getChange = function () {
return this.$change;
};
MP.setFinish = function (f) {
this.$change = f - this.$begin;
};
MP.getFinish = function () {
return this.$begin + this.$change;
};
with (MP) {
addProperty ("obj", getObj, setObj);
addProperty ("prop", getProp, setProp);
addProperty ("func", getFunc, setFunc);
addProperty ("begin", getBegin, setBegin);
addProperty ("finish", getFinish, setFinish);
addProperty ("duration", getDuration, SetDuration);
addProperty ("useSeconds", getUseSeconds, setUseSeconds);
addProperty ("looping", getLooping, setLooping);
addProperty ("prevPos", getPrevPos, null);
addProperty ("change", getChange, setChange)
addProperty ("time", getTime, setTime);
addProperty ("position",function(){return this.getPosition();},
function(p){this.setPosition(p);}
)
}
delete MP;
tfx = "Motion and Tween class loaded";
this.onMouseUp = function(){
xtween = new Tween(ball_mc,"_x","easeOut",_xmouse,60,400,true);
this.onEnterFrame = function (){trace (xtween);}
}
function easeOut (t:Number, b:Number, c:Number, d:Number):Number {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
} Code: MP.getPosition = function (t) {
if (t == undefined) {t = this.$time;}
with (this) return $func (t,
$begin,
$change,
$duration);
}; Code: addProperty ("position",
function (){return this.getPosition();},
function (p){this.setPosition(p);}) hätte jemand die Muse mir mit nem kurzen Schlag auf den Hinterkopf zu zeigen wie ich das anstellen soll? Danke im Vorraus , Gruss lackschuh98... |
| | |
| | #3 (permalink) |
| Neuer User Registriert seit: Jul 2006
Beiträge: 7
|
Ähm bin jetzt nicht so der Scriptheld aber wenn ich mir die Tween Klasse aus mx so anschaue weicht die nicht wirklich davon ab was die funktionen angeht . Also ich habs soweit das der mc schon mal an den Anfangspunkt des Tweens gesetzt wird nur läuft die Zeit dann nicht weiter weil wahrscheinlich die OnEnterFrame Schleife nicht ausgelöst wird , das wird meines Wissens durch den Listener bewältigt , wozu ich aber wohl noch die Klassen mx.transitions.BroadcasterMX mx.transitions.OnEnterFrameBeacon umschreiben muss , was ich definitiv nicht hinkrieg weil dort ja ständig wieder verweise auf die mx Klassen sind und ich so tief dann auch nicht in der Materie stecke... mir raucht ein wenig das Hirn , hehe... |
| | |
![]() |
| Lesezeichen |
| Themen-Optionen | |
| Ansicht | |
| |