Mi versión de los tweens, usando las ecuaciones de Robert Penner.
Actionscript:
MovieClip.prototype.easeInOut = function(t:Number, b:Number, c:Number, d:Number):Number {
if ((t /= d/2)<1) {
return c/2*t*t*t*t*t+b;
}
return c/2*((t -= 2)*t*t*t*t+2)+b;
};
MovieClip.prototype.myTween = function(prop, destino, duracion) {
var dummy:MovieClip = this._parent.createEmptyMovieClip("dummy"+random(5000), this._parent.getNextHighestDepth());
este = this;
dummy.propini = this[prop];
dummy.dx = destino-this[prop];
dummy.t = 5;
dummy.duracion = duracion;
dummy.onEnterFrame = function() {
if (this.t++<duracion) {
este[prop] = este.easeInOut(this.t, this.propini, this.dx, this.duracion);
} else {
delete this.onEnterFrame;
removeMovieClip(this);
}
};
};
//Uso:
_root.onMouseDown = function() {
obj_mc.myTween("_x", _root._xmouse, 50);
obj_mc.myTween("_y", _root._ymouse, 50);
};
Este prototipo crea un marco del grosor y color definidos en sus parámetros sobre el movieClip en que se aplica. También asigna métodos onRollOver y onRollOut a dicho movieClip para escalar el grosor del marco.
Requiere la librería de
Laco,
Zeh, o similar.
Descargable frameOver prototype
Actionscript:
#include "lmc_tween.as"
MovieClip.prototype.frameOver = function(grosor,color) {
var over:MovieClip = this.createEmptyMovieClip("over", 1);
var l:MovieClip = over.createEmptyMovieClip("l", 1);
var escalax = (this._width+grosor*2)/100*grosor;
var escalay = this._height/100*grosor*2;
var w:Number = this._width;
var h:Number = this._height;
l.lineStyle(0, 0x000000, 0);
l.beginFill(color, 100);
l.moveTo(0, -h/2);
l.lineTo(grosor, -h/2);
l.lineTo(grosor, h/2);
l.lineTo(0, h/2);
l.lineTo(0, -h/2);
l.endFill();
l._y = h/2;
l._xscale = .1;
var t:MovieClip = l.duplicateMovieClip("t", 2, {_x:w/2, _y:0, _rotation:90});
var r:MovieClip = l.duplicateMovieClip("r", 3, {_x:w, _y:h/2, _rotation:180});
var b:MovieClip = l.duplicateMovieClip("b", 4, {_x:w/2, _y:h, _rotation:270});
t._yscale = b._yscale=w/h*100;
this.onRollOver = function() {
l.tween("_xscale", 100, 1);
t.tween("_xscale", 100, 1);
r.tween("_xscale", 100, 1);
b.tween("_xscale", 100, 1);
};
this.onRollOut = function() {
l.tween("_xscale", .1, .5);
t.tween("_xscale", .1, .5);
r.tween("_xscale", .1, .5);
b.tween("_xscale", .1, .5);
};
};
//Uso:
obj_mc.frameOver(15,0x666666);
Si viera esto Laco probablemente me cortaría la coleta, pero el otro día estaba ajustando el peso de unas creatividades y no tuve más remedio que sacar Kb de donde no había eliminando los métodos que no me resultaban extrictamente necesarios de la clase "tween" de Laco. Esto fue lo que quedo.
Actionscript:
if (_global.$tweenManager == undefined) {
_global.$tweenManager = new zigo.tweenManager();
} else {
_global.$tweenManager.playing = false;
}
var Mp = MovieClip.prototype;
Mp.addListener = function() {
if (!this._listeners) {
AsBroadcaster.initialize(this);
}
this.addListener.apply(this, arguments);
};
ASSetPropFlags(Mp, "addListener", 1, 0);
// == core methods ==
Mp.tween = function(props, pEnd, seconds, animType, delay, callback, extra1, extra2) {
if (typeof (props) == "string") {
props = [props];
}
if (pEnd.length == undefined) {
pEnd = [pEnd];
}
// parse animtype to reference to equation function
switch (typeof (animType)) {
case "string" :
//string
animType = animType.toLowerCase();
if (eqf == undefined) {
// set default tweening equation
var eqf = com.robertpenner.easing.Expo.easeInOut;
}
break;
case "function" :
// function
var eqf = animType;
break;
case "object" :
// object from custom easing
if (animType.ease != undefined && animType.pts != undefined) {
var eqf = animType.ease;
extra1 = animType.pts;
} else {
var eqf = com.robertpenner.easing.Expo.easeInOut;
}
break;
default :
var eqf = com.robertpenner.easing.Expo.easeInOut;
}
// parse callback function
if (_global.$tweenManager.autoStop) {
// automatic removing tweens as in Zeh proto
_global.$tweenManager.removeTween(this, props);
}
if (delay>0) {
_global.$tweenManager.addTweenWithDelay(delay, this, props, pEnd, seconds, eqf, callback, extra1, extra2);
} else {
_global.$tweenManager.addTween(this, props, pEnd, seconds, eqf, callback, extra1, extra2);
}
};
ASSetPropFlags(Mp, "tween", 1, 0);
delete Mp;
Muy criticable, lo sé, debi hacerme mi propia versión pero el tiempo es el que hay, y al igual que con los Kb, lo acabas sacando de donde no hay.
Sistema de menú con submenus generados dinámicamente (hasta 2 niveles) que tira de pseudoxml. Toda la navegación se realiza a través de la función fNavTo.
Actionscript:
stop();
#include "lmc_tween.as"
secciones_xml = new XML("<secciones><seccion tit='Inicio'></seccion><seccion tit='Nokia E61'><item tit='Presentación'/><item tit='Ficha Técnica'/><item tit='Galería'/><item tit='Zoom'/></seccion><seccion tit='Real Mail Profesional'><item tit='Qué es'/><item tit='Consejos prácticos'/></seccion><seccion tit='Actívalo ahora'><item tit='Registro e instalación'/><item tit='Acceso al servicio'/></seccion></secciones>");
sec_ar = new Array("inicio", "nokiaE61", "realmail", "activalo");
fMenu = function () {
for (var i = 0; i<secciones_xml.firstChild.childNodes.length; i++) {
var submenu:MovieClip = holder_menu_mc.createEmptyMovieClip("submenu"+i, i);
submenu._y = 16*i;
submenu.miID = i;
var btn_menu:MovieClip = submenu.attachMovie("btn_menu", "btn_menu", 0);
btn_menu.txt.text = secciones_xml.firstChild.childNodes[i].attributes.tit;
btn_menu.miID = i;
btn_menu.miTipo = "m";
btn_menu.onRelease =btn_menu.onReleaseOutside = fReleaseM;
btn_menu.onRollOver = fRollOver;
btn_menu.onRollOut = fRollOut;
}
};
fRollOver = function () {
if (this != selectedSMbtn && this != selectedMbtn) {
this.colorTo(0x999999, .1,"linear");
}
};
fRollOut = function () {
if (this != selectedSMbtn && this != selectedMbtn) {
this.colorTo(0x666666,1,"easeOutQuad");
}
};
fSelectBtn = function (cual) {
selectedSMbtn.colorTo(0x666666, .1, "easeInQuad");
if (cual.miTipo=="m" && cual.miID != selectedMbtn.miID) {
selectedMbtn.colorTo(0x666666, 1, "easeOutQuad");
}
selectedMbtn.enabled = true;
selectedSMbtn.enabled = true;
cual.enabled = false;
cual.colorTo(0xFF0000, .1, "linear");
};
fReleaseM = function () {
fSelectBtn(this);
if (_root.secnow != undefined) {
fCierraSM();
}
fAbreSM(this.miID);
fNavTo(this.miID);
selectedMbtn = this;
};
fReleaseSM = function () {
fSelectBtn(this);
fNavTo(this._parent.miID, this.miID);
selectedSMbtn = this;
};
fNavTo = function (sec, subsec) {
trace(sec_ar[sec]+"/"+subsec);
};
fAbreSM = function (cual) {
var posy:Number = 0;
for (var j = 0; j<secciones_xml.firstChild.childNodes[cual].childNodes.length; j++) {
var btn_submenu:MovieClip = holder_menu_mc["submenu"+cual].attachMovie("btn_submenu", "btn_submenu"+j, j+1);
btn_submenu.miTipo = "s";
btn_submenu.miID = j;
btn_submenu._y = 16*j+16;
btn_submenu.txt.text = "> "+secciones_xml.firstChild.childNodes[cual].childNodes[j].attributes.tit;
btn_submenu.onRelease =btn_submenu.onReleaseOutside = fReleaseSM;
btn_submenu.onRollOver = fRollOver;
btn_submenu.onRollOut = fRollOut;
}
for (var i = 0; i<secciones_xml.firstChild.childNodes.length; i++) {
if (i>cual) {
holder_menu_mc["submenu"+i]._y += j*16;
}
}
_root.secnow = cual;
};
fCierraSM = function () {
for (var j = 0; j<secciones_xml.firstChild.childNodes[_root.secnow].childNodes.length; j++) {
var btn_submenu:MovieClip = holder_menu_mc["submenu"+_root.secnow]["btn_submenu"+Number(j)];
btn_submenu.removeMovieClip();
}
for (var i = 0; i<secciones_xml.firstChild.childNodes.length; i++) {
if (i>_root.secnow) {
holder_menu_mc["submenu"+i]._y -= j*16;
}
}
};
fMenu();
Descarga menu.fla
Genera un temblor en la cantidad definida por el parámetro value. Si se usa sin parámetros detiene el temblor.
Actionscript:
MovieClip.prototype.shake = function(value) {
if (value) {
this.orgX = this._x;
this.orgY = this._y;
this.onEnterFrame = function() {
this._x = this.orgX+Math.random()*(value*2)-value;
this._y = this.orgY+Math.random()*(value*2)-value;
};
} else {
delete this.onEnterFrame;
this._x = this.orgX;
this._y = this.orgY;
}
};
//Uso 1
obj_mc.shake(5);//provoca un temblor de 5 pixeles
//Uso 2
obj_mc.shake();//detiene temblor
Enlaces relacionados: No related posts, | Tags:
actionscript,
prototipo,
efecto,
comportamiento,
shake,
MovieClip
Aplicado sobre un movieClip, este rehuye el mouse, en función de la distancia especificada en el parámetro distance.
Actionscript:
MovieClip.prototype.avoidMouse = function(distance, speed, accel) {
distx = this._parent._xmouse-this._x;
disty = this._parent._ymouse-this._y;
distanceh = Math.sqrt((distx*distx)+(disty*disty));
if (distanceh<distance) {
var angle = Math.atan2(disty, distx);
if (accel) {
speed = Math.min(speed, accel*distance/distance);
}
this._x -= Math.cos(angle)*speed;
this._y -= Math.sin(angle)*speed;
}
};
//Uso:
obj_mc.onEnterFrame = function() {
this.avoidMouse(100, 10, 10);
};
Enlaces relacionados: No related posts, | Tags:
prototipo,
comportamiento,
actionscript,
MovieClip
Código de movimiento parabólico, generosamente publicado por Eliseo en After hours
Actionscript:
_root.onMouseDown = function() {
mimc.x0 = mimc._x;
mimc.y0 = mimc._y;
mimc.t1 = 30;
mimc.x1 = _xmouse;
mimc.y1 = _ymouse;
g = 2;
mimc.t = 0;
mimc.vx0 = (mimc.x1-mimc.x0)/mimc.t1;
mimc.vy0 = (mimc.y1-mimc.y0-g*mimc.t1*mimc.t1/2)/mimc.t1;
mimc.onEnterFrame = function() {
this._x = this.x0+this.t*this.vx0;
this._y = this.y0+this.t*this.vy0+g*this.t*this.t/2;
if (this.t == this.t1) {
delete this.onEnterFrame;
} else {
this.t++;
}
};
};
Enlaces relacionados: No related posts, | Tags:
actionscript,
prototipo,
comportamiento
Prototipo "made by drus" para hacer parpadear un movieClip.
Actionscript:
MovieClip.prototype.blink = function(veces, vel, fin) {
obj = this;
obj.n = obj._visible;
obj.cont = 0;
vel == undefined ? obj.vel=100 : obj.vel=vel;
this.id = setInterval(function () {
obj.cont += 1;
if (obj.cont<=veces*2) {
obj._visible = !obj._visible;
} else {
if (fin == undefined) {
fin = true;
}
obj._visible = fin;
clearInterval(obj.id);
}
}, this.vel);
};
Prototipo "made by drus" para dar a cualquier movieClip propiedades de icono: drag&drop, dobleclick...
Actionscript:
MovieClip.prototype.icono = function(milabel, handler) {
_global.icoDepth=0;
this.useHandCursor = false;
this.onPress = function() {
_global.icoDepth++;
this.swapDepths(_global.icoDepth);
startDrag(this);
this.time = new Date();
this.clickTimeb = this.time.getTime();
this.doubleClick = (this.clickTimeb-this.clickTimea);
if (this.doubleClick<400) {
handler(milabel);
}
this.clickTimea = this.time.getTime();
};
this.onRelease = this.onReleaseOutside=function () {
stopDrag();
};
var label_fm:TextFormat = new TextFormat();
label_fm.align = "center";
label_fm.font = "_sans";
label_fm.size = 10;
this.createTextField("label_txt", 1, -10, 0, 20, 30);
this.label_txt.autoSize = "center";
//this.label_txt.border = true;
this.label_txt.text = milabel;
this.label_txt.setTextFormat(label_fm);
};
//Uso:
handlerFunction = function (cual) {
trace("dobleClick "+cual);
};
ico_misdocs_mc.icono("Mis documentos", handlerFunction);
ico_papelera_mc.icono("Papelera", handlerFunction);
Enlaces relacionados: No related posts, | Tags:
actionscript,
prototipo,
comportamiento,
MovieClip
—
Siguiente página »