Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/05/2007, 10:00
Avatar de andrewp
andrewp
 
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 1.160
Antigüedad: 20 años, 8 meses
Puntos: 5
Zoom que se pierde...

He tomado "prestado" un código de un tutorial para realizar un zoom dinámico, reset de la imagen, drag and drop, etc. La verdad es que funciona de maravilla salvo algunas cosillas que me gustaría que me ayudaran a resolver.

El código principal es el siguiente:

Cita:
#include "movimientos.as"
sententido = cuanto=2
mano = dir =false;
scale =100;
finalx=finaly=500
ecuacion="easeInOutQuad";
vel = 30;
Mouse.hide();
MovieClip.prototype.dibujaRectangulo = function(width, height, x, y) {
this.moveTo(x, y);
this.lineTo(width, y);
this.lineTo(width, height);
this.lineTo(x, height);
this.lineTo(x, y);
};
function escalar (xReceptor,yReceptor,xOriginal,yOriginal,rellenar) {
var xscale = xReceptor/xOriginal;
var yscale = yReceptor/yOriginal;
if (rellenar) return Math.max(xscale,yscale)* 100;
else return Math.min(xscale,yscale)* 100;
};
cuad=mapa.foto.createEmptyMovieClip("cuadrado", 1);
//Zoom
mapa.onPress = function() {
if(mano){
this.startDrag();
}else{
this.inix = this.foto._xmouse;
this.iniy = this.foto._ymouse;
this.onEnterFrame = function() {
cuad.clear();
cuad.lineStyle(.4, 0xffffff,50);
cuad.dibujaRectangulo(this.foto._xmouse, this.foto._ymouse,
this.inix, this.iniy);
};
};
};
mapa.onRelease = mapa.onReleaseOutside= function() {
if(mano){
this.stopDrag();
}else{
this.inix = Math.min(this.inix,this.foto._xmouse);
this.iniy = Math.min(this.iniy,this.foto._ymouse);
delete this.onEnterFrame;
if (cuad._width*scale/100>10 || cuad._height*scale/100>10){
this.foto.mover(ecuacion, vel, 0, {
_x:-this.inix-(cuad._width/2),
_y:-this.iniy-(cuad._height/2)
});
scale=escalar(finalx,finaly,cuad._width,cuad._heig ht);
this.mover(ecuacion, vel, 0, {
_xscale:scale , _yscale:scale,
_x:finalx/2, _y:finaly/2
},
function(){cuad.clear();});
}else{
cuad.clear();
scale *= sententido;
this.foto.mover(ecuacion, vel, 0, {
_x:-this.foto._xmouse,
_y:-this.foto._ymouse
});
this.mover(ecuacion, vel, 0, {
//aplicamos scale
_xscale:scale , _yscale:scale,
_x:this._parent._xmouse, _y:this._parent._ymouse
});
}
}
};
//Magnifying Glass
function verLupa(){
if(!mano){
_root.lupa._visible = true;
Mouse.hide();
_root.onMouseMove = function() {
_root.lupa.moverIni({_x:this._xmouse, _y:this._ymouse});
updateAfterEvent();
};
}
};
function esconderLupa(){
_root.lupa._visible = false;
Mouse.show();
delete _root.onMouseMove ;
};
verLupa();
//Buttons
btZoom.onPress = function() {
if (mano) {
btMano.activado = mano=false;
btMano._alpha = 100;
} else {
if (dir) sententido = cuanto;
else sententido = 1/cuanto;
dir = !dir;
this.gotoAndStop(dir+1);
this._parent.lupa.gotoAndStop(dir+1);
}
};
btMano.onPress = function() {
this.activado = !this.activado;
if (this.activado) {
mano = true;
esconderLupa();
this._alpha = 50;
} else {
mano = false;
verLupa();
this._alpha = 100;
}
};
//stand by of Magnifying glass I
marque.onRollOver=function() {
esconderLupa();
this.useHandCursor = true;
}
marque.onRollOut = verLupa;
btMano.onRollOver=esconderLupa;
btMano.onRollOut = verLupa;
btZoom.onRollOver=esconderLupa;
btZoom.onRollOut = verLupa;

//stand by of Magnifying glass II
barPepe.onRollOver=function() {
esconderLupa();
this.useHandCursor = true;
}
barPepe.onRollOut = verLupa;
btMano.onRollOver=esconderLupa;
btMano.onRollOut = verLupa;
btZoom.onRollOver=esconderLupa;
btZoom.onRollOut = verLupa;
//Reset
btReset.onRollOver=esconderLupa;
btReset.onRollOut = verLupa;
btReset.onPress = function() {
trace(this._parent.mapa._x+" - "+this._parent.mapa._y)
this._parent.mapa.foto.mover(ecuacion, vel, 0, {
_x:0,
_y:0
});
this._parent.mapa.mover(ecuacion, vel, 0, {
_xscale:scale=100 , _yscale:100,
_x:6.5, _y: 0.0
});
}
El problemilla es:
Los bordes de la imagen se ven, no sé si es posible "fijar" el espacio mínimo del zoom para que siempre se vea a la escala inicial de la animación. y el zoom negativo no haga que el mapa se reduzca y se pierda de vista.

Gracias por vuestra ayuda.
__________________
Andrew :P