Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 25-06-2007, 15:11   #1
zUmBo!
Member
 
L'Avatar di zUmBo!
 
Iscritto dal: Jan 2003
Città: Bologna
Messaggi: 219
Strano comportamento in Actionscript setInterval

Salve a tutti,

ho creato un codice in Actionscript che mi permette di alzare l'altezza di un oggetto quando la coordinata X del mouse coincide con la coordinate x occupate dall'oggetto.

Ho creato anche il codice che abbassa l'altezza dell'oggetto nel caso le cooordinate non coincidessero più.

ora arriva la cosa strana:

queste 2 funzioni FUNZIONANO! ma una alla volta.

Se le richiamo tutte e 2 succede un macello, cioè la prima chiamata in causa funziona benissimo, la seconda da un errore, cioè cambia ripetutamente l'altezza dell'oggetto (effetto stroboscopica).

secondo voi, maghi di javascript/actionscript, dov'è l'inghippo?


questo funziona, e abbassa correttamente l'oggetto:
Codice:
var target = this;
this._height=60;
onMouseMove = function () {
	/*if ((target._xmouse>=-3) && (target._xmouse<=12)) {
		target.IdAlza = setInterval(alza, 10, target);
		clearInterval(target.idAbbassa);
	}*/
	if ((target._xmouse<-3) || (target._xmouse>12)) {
		target.IdAbbassa = setInterval(abbassa, 50, target);
		clearInterval(target.idAlza);
	}
	
	
};
//FUNZIONI
function alza(target) {
	if (target._height<60) {
		target._height += 1;
	}
}
function abbassa(target) {
	if (target._height>6) {
		target._height -= 1;
	}
}

quest'altro funziona e alza l'oggetto
Codice:
var target = this;
//this._height=60;
onMouseMove = function () {
	if ((target._xmouse>=-3) && (target._xmouse<=12)) {
		target.IdAlza = setInterval(alza, 10, target);
		clearInterval(target.idAbbassa);
	}
	/*if ((target._xmouse<-3) || (target._xmouse>12)) {
		target.IdAbbassa = setInterval(abbassa, 50, target);
		clearInterval(target.idAlza);
	}*/
	
	
};
//FUNZIONI
function alza(target) {
	if (target._height<60) {
		target._height += 1;
	}
}
function abbassa(target) {
	if (target._height>6) {
		target._height -= 1;
	}
}

attivando entrambe le funzioni succede il macello
Codice:
var target = this;
//this._height=60;
onMouseMove = function () {
	if ((target._xmouse>=-3) && (target._xmouse<=12)) {
		target.IdAlza = setInterval(alza, 10, target);
		clearInterval(target.idAbbassa);
	}
	if ((target._xmouse<-3) || (target._xmouse>12)) {
		target.IdAbbassa = setInterval(abbassa, 50, target);
		clearInterval(target.idAlza);
	}
	
	
};
//FUNZIONI
function alza(target) {
	if (target._height<60) {
		target._height += 1;
	}
}
function abbassa(target) {
	if (target._height>6) {
		target._height -= 1;
	}
}
grazie in anticipo a tutti coloro che cercheranno di aiutarmi
__________________
“Il vero viaggio di scoperta non consiste nel cercare nuove terre, ma nell'avere nuovi occhi.”

Marcel Proust

Ultima modifica di zUmBo! : 25-06-2007 alle 15:15.
zUmBo! è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 01:39.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v