Foros del Web » Creando para Internet » Flash y Actionscript »

Ayuda con este script AS

Estas en el tema de Ayuda con este script AS en el foro de Flash y Actionscript en Foros del Web. Buenas a todos. Os suplico ayuda urgente con un script en AS. Veréis tengo un menú vertical que se mueve hacia a arriba o hacia ...
  #1 (permalink)  
Antiguo 16/06/2007, 10:17
Vbx
 
Fecha de Ingreso: junio-2007
Mensajes: 2
Antigüedad: 16 años, 10 meses
Puntos: 0
Ayuda con este script AS

Buenas a todos.

Os suplico ayuda urgente con un script en AS. Veréis tengo un menú vertical que se mueve hacia a arriba o hacia abajo según la posición del ratón (típio). Me gustó mucho el script (no es mío) y lo he utilizado algunas veces en algunos trabajos. Mi problema ha sido cuando he intentado hacer que cuando llegue al límite inferior o superior se pare, en lugar de rebotar e ir hacia el lado contrario.

Me explico; supongamos que tengo un espacio vertical de 400 px., cuando el primer boton del movie clip que contiene los botones del menú llega al límite superior (coord. Y con valor 10) debe de pararse, y cuando el último botón llega al límite inferior (coord. Y con valor 390) también debería de pararse. El problema es que este script está pensado para que cuando se llega a un límite (sea superior o inferior) automáticamente "rebote" y continúe en el sentido contrario.

Os pongo el script:

En el primer frame de la película:
Código:
var bxi = 0;
//Holds current speed of scrolling menu					
var stageH = Stage.height;
var midStage = mouseBuffer=stageH/2;
/* midStage holds the pixels located in the middle 
   of the stage 									*/
/* Declare a mouse listener object, have onMouseMove event handler point to the 
directMenu function and then add listener via addListener(...)				 */
mouseListener = new Object();
mouseListener.onMouseMove = directMenu;
Mouse.addListener(mouseListener);
//Declare and define the directMenu function 
function directMenu() {
	/* mouseBuffer stores the y coordinate of the mouse point from the last 
	mouse move event. Then on the next mouse move the following code checks
	the current y coordinate of the mouse pointer with the one previously 
	stored in the mouseBuffer and takes appropriate actions              */
	if (mouseBuffer>_ymouse) {
		/* If mouseBuffer is greater that means that you moved up so move
		so move menu down by adding to bxi. If the ymouse is less than the 
		the middle of the stage increase scrolling speed.                */
		if (_ymouse<midStage) {
			bxi = bxi+0.09;
		} else {
			bxi = bxi+0.06;
		}
	} else if (mouseBuffer<_ymouse) {
		if (_ymouse>midStage) {
			bxi = bxi-0.09;
		} else {
			bxi = bxi-0.06;
		}
	}
	mouseBuffer = _ymouse;
}
Y como evento "enterFrame" dentro del movie clip que contiene el menú en si:
Código:
onClipEvent (enterFrame) {
	//Posicion Y actual
	ty = this._y;
	//Tamaño vertical del menu
	tw = this._height;
	//Pregunta si la suma de Y actual y el tamaño vertical son mayor o igual
	if (ty+tw>=_root.stageH+tw/6.1) {
		///trace("toco arriba");
		_root.bxi = -(0.5);
	} else if (ty<=-(tw/5.5)) {
		//trace("toco abajo");
		_root.bxi = +0.5;
	}
	this._y = this._y+_root.bxi;
}
Este es el código. Ahora mismo lo que hace, como he dicho, es rebotar cuando llega al límite superior o inferior.

Necesito que al llegar a dicho límite (el cual es variable porque el menú es desplegable) se pare, y al mover el ratón hacia la dirección contraria vuelva a moverse hasta llegar a otro límite de nuevo.

Espero haberme explicado.

Os doy mis más sinceras GRACIAS por adelantado.

Saludos.
  #2 (permalink)  
Antiguo 17/06/2007, 04:31
 
Fecha de Ingreso: mayo-2006
Mensajes: 77
Antigüedad: 17 años, 10 meses
Puntos: 1
Re: Ayuda con este script AS

a ver que tal esto:
Cita:
onClipEvent (enterFrame) {
//Posicion Y actual
ty = this._y;
//Tamaño vertical del menu
tw = this._height;
//Pregunta si la suma de Y actual y el tamaño vertical son mayor o igual
if (ty+tw>=_root.stageH+tw/6.1 and _root.bxi>0) {
//trace("toco arriba");
return;
} else if (ty<=-(tw/5.5) and _root.bxi<0) {
//trace("toco abajo");
return;
}
this._y = this._y+_root.bxi;
}
Lo que hace es añadir otra comparación:

"si está en el límite y la direccion no es la correcta", sale de la funcion sin mover.

Un saludo
  #3 (permalink)  
Antiguo 17/06/2007, 09:27
Vbx
 
Fecha de Ingreso: junio-2007
Mensajes: 2
Antigüedad: 16 años, 10 meses
Puntos: 0
Re: Ayuda con este script AS

Muchisimas gracias.

Ahora funciona perfectamente.

De verdad GRACIAS de nuevo :)

Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:04.