Vom Prototype zur Klasse [Flash 7]
| Beiträge: 130 Wohnort: Berlin/Germany Registriert: Mar 2002
| 06.02.2005, 12:10
Vom Prototype zur Klasse und den diversen Lösungsansätzen.
ActionScript 1.0
Hier haben wir den Wabber-Prototype, welcher direkt im Flash Film untergebracht wird. Es wird ein MovieClip-Symbol mit dem Verknüpfungsbezeichner Clip und zwei MovieClip-Instanzen mc und mc2 benötigt.
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | MovieClip.prototype.wabber = function(multiplikator, xskal, yskal, ratio) {
if (this.sX == undefined) this.sX = 0;
if (this.sY == undefined) this.sY = 0;
this.onEnterFrame = function() {
this.sX = Number(this.sX*multiplikator)+Number((xskal-this._xscale)*ratio);
this.sY = Number(this.sY*multiplikator)+Number((yskal-this._yscale)*ratio);
this._xscale += Math.round(this.sX);
this._yscale += Math.round(this.sY);
};
};
MovieClip.prototype.wabberKill = function(multiplikator, xskal, yskal, ratio) {
if (this.sX == undefined) this.sX = 0;
if (this.sY == undefined) this.sY = 0;
this.onEnterFrame = function() {
if (this._xscale != xskal || this._yscale != yskal) {
this.sX = Number(this.sX*multiplikator)+Number((xskal-this._xscale)*ratio);
this.sY = Number(this.sY*multiplikator)+Number((yskal-this._yscale)*ratio);
this._xscale += Math.round(this.sX);
this._yscale += Math.round(this.sY);
} else {
delete this.onEnterFrame;
}
};
};
// Clip Wabber
mc.wabber(.9, 150, 150, .3);
mc.onRollOver = function() {
this.wabber(.9, 150, 150, .3);
};
mc.onRollOut = function() {
this.wabber(.9, 100, 100, .3);
};
// Clip WabberKill
mc_2.wabberKill(.9, 150, 150, .3);
mc_2.onRollOver = function() {
this.wabberKill(.9, 150, 150, .3);
};
mc_2.onRollOut = function() {
this.wabberKill(.9, 100, 100, .3);
};
|
----
ActionScript 2.0
Hier haben wir drei ActionScript 2.0 Lösungsansätze (Simple, Register, Comp).
Simple-Version Wabber.as - Skript
Diese Version gehört zur Standard-Lösung. Die Klasse Wabber wird hierbei von der MovieClip-Klasse abgeleitet.
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | class Wabber extends MovieClip {
// Prop
private var sX:Number;
private var sY:Number;
// Constructor
function Wabber() {}
// Effekt wabbern
public function wabbern(multiplikator:Number, xskal:Number, yskal:Number, ratio:Number):Void {
if (sX == undefined) sX = 0;
if (sY == undefined) sY = 0;
onEnterFrame = function() {
sX = Number(sX*multiplikator)+Number((xskal-_xscale)*ratio);
sY = Number(sY*multiplikator)+Number((yskal-_yscale)*ratio);
_xscale += Math.round(sX);
_yscale += Math.round(sY);
};
}
// Effekt wabbern_kill
public function wabbern_kill(multiplikator:Number, xskal:Number, yskal:Number, ratio:Number):Void {
if (sX == undefined) sX = 0;
if (sY == undefined) sY = 0;
onEnterFrame = function() {
if (_xscale != xskal || _yscale != yskal) {
sX = Number(sX*multiplikator)+Number((xskal-_xscale)*ratio);
sY = Number(sY*multiplikator)+Number((yskal-_yscale)*ratio);
_xscale += Math.round(sX);
_yscale += Math.round(sY);
} else {
delete onEnterFrame;
}
};
}
}
|
Flash Film Simple-Version - Skript
Flash Film (es wird lediglich ein Movieclip-Symbol mit dem Verknüpfungsbezeichner Clip vorausgesetzt) - die Verknüpfung zur Klasse muss ebenfalls zugewiesen werden.
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Clip wabber
mc.wabbern(.9, 150, 150, .3);
mc.onRollOver = function()
{
this.wabbern(.9, 150, 150, .3);
}
mc.onRollOut = function()
{
this.wabbern(.9, 100, 100, .3);
}
// Clip wabbern_kill
mc_2.wabbern_kill(.9, 150, 150, .3);
mc_2.onRollOver = function()
{
this.wabbern_kill(.9, 150, 150, .3);
}
mc_2.onRollOut = function()
{
this.wabbern_kill(.9, 100, 100, .3);
}
|
Dyn-Version Wabber.as - Skript
Wie man sieht wird die Klasse Wabber von der Klasse MovieClip abgeleitet!
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | class Wabber extends MovieClip {
// Prop
private var sX:Number;
private var sY:Number;
// Constructor
public function Wabber() {}
// Effekt wabbern
public function wabbern(multiplikator:Number, xskal:Number, yskal:Number, ratio:Number):Void {
if (sX == undefined) sX = 0;
if (sY == undefined) sY = 0;
onEnterFrame = function() {
sX = Number(sX*multiplikator)+Number((xskal-_xscale)*ratio);
sY = Number(sY*multiplikator)+Number((yskal-_yscale)*ratio);
_xscale += Math.round(sX);
_yscale += Math.round(sY);
};
}
// Effekt wabbern_kill
public function wabbern_kill(multiplikator:Number, xskal:Number, yskal:Number, ratio:Number):Void {
if (sX == undefined) sX = 0;
if (sY == undefined) sY = 0;
onEnterFrame = function() {
if (_xscale != xskal || _yscale != yskal) {
sX = Number(sX*multiplikator)+Number((xskal-_xscale)*ratio);
sY = Number(sY*multiplikator)+Number((yskal-_yscale)*ratio);
_xscale += Math.round(sX);
_yscale += Math.round(sY);
} else {
delete onEnterFrame;
}
};
}
}
|
Flash Film Dyn-Version - Skript
Flash Film (es wird lediglich ein Movieclip-Symbol mit dem Verknüpfungsbezeichner Clip vorausgesetzt) - die Verknüpfung zur Klasse übernimmt Object.registerClass()
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // Symbol Clip und Wabber-Klasse
Object.registerClass("Clip", Wabber);
// MC
this.attachMovie ("Clip", "mc", 1, {_x:160, _y:200});
mc.wabbern(.9, 150, 150, .3);
mc.onRollOver = function()
{
this.wabbern(.9, 150, 150, .3);
}
mc.onRollOut = function()
{
this.wabbern(.9, 100, 100, .3);
}
// MC2
this.attachMovie ("Clip", "mc2", 2, {_x:410, _y:200});
mc2.wabbern_kill(.9, 150, 150, .3);
mc2.onRollOver = function()
{
this.wabbern_kill(.9, 150, 150, .3);
}
mc2.onRollOut = function()
{
this.wabbern_kill(.9, 100, 100, .3);
}
|
Comp-Version Wabber.as - Skript
Eine Ableitung von der Klasse MovieClip ist in diesem Fall nicht notwendig.
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | class Wabber {
// Prop
private var ziel:MovieClip;
// Constructor
public function Wabber(ziel:MovieClip)
{
this.ziel = ziel;
}
// Effekt wabbern
public function wabbern(multiplikator:Number, xskal:Number, yskal:Number, ratio:Number):Void {
if (ziel.sX == undefined) ziel.sX = 0;
if (ziel.sY == undefined) ziel.sY = 0;
ziel.onEnterFrame = function() {
this.sX = Number(this.sX*multiplikator)+Number((xskal-this._xscale)*ratio);
this.sY = Number(this.sY*multiplikator)+Number((yskal-this._yscale)*ratio);
this._xscale += Math.round(this.sX);
this._yscale += Math.round(this.sY);
};
}
// Effekt wabbern_kill
public function wabbern_kill(multiplikator:Number, xskal:Number, yskal:Number, ratio:Number):Void {
if (ziel.sX == undefined) ziel.sX = 0;
if (ziel.sY == undefined) ziel.sY = 0;
ziel.onEnterFrame = function() {
if (this._xscale != xskal || this._yscale != yskal) {
this.sX = Number(this.sX*multiplikator)+Number((xskal-this._xscale)*ratio);
this.sY = Number(this.sY*multiplikator)+Number((yskal-this._yscale)*ratio);
this._xscale += Math.round(this.sX);
this._yscale += Math.round(this.sY);
} else {
delete this.onEnterFrame;
}
};
}
}
|
Flash Film Comp-Version - Skript
Flash Film (es wird lediglich ein Movieclip-Symbol mit dem Verknüpfungsbezeichner Clip vorausgesetzt) - die Verknüpfung zum MovieClip übernimmt die Klasse selbst.
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // Clip Objekt
var clip:Wabber = new Wabber(this.mc);
clip.wabbern(.9, 150, 150, .3);
mc.onRollOver = function()
{
clip.wabbern(.9, 150, 150, .3);
}
mc.onRollOut = function()
{
clip.wabbern(.9, 100, 100, .3);
}
// Clip2 Objekt
var clip2:Wabber = new Wabber(this.mc2);
clip2.wabbern_kill(.9, 150, 150, .3);
mc2.onRollOver = function()
{
clip2.wabbern_kill(.9, 150, 150, .3);
}
mc2.onRollOut = function()
{
clip2.wabbern_kill(.9, 100, 100, .3);
}
|
Be inspired!
Liebe Grüsse
Matze K.
[Flashstar]
http://www.flashstar.de[Flashstar]
http://www.flashstar.de | Geändert von Madokan am 06.02.05 um 12:11 Uhr | |
|
| Ähnliche Beiträge zum Thema | |
|
Flashhilfe.de Flash Platform Tipps & Tutorials Flash Platform Andere Programmiersprachen Jobangebote Diskussionen
Flashhilfe News 
Regeln & Bedingungen
|