Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[flash mx 2004] c'est un bug ou c'est moi ?

2 réponses
Avatar
seb
Salut,

J'ai un truc bizarre qui se produit dans un script.

Voilà le problème (après simplification du code) :
- j'ai un mc nommé "test"
- j'ai le code ci-dessous dans la 1ere frame
- le comportement est normal pour les zone haut/gauche et bas/droite c'est à
dire que le mc s'agrandit de manière cohérente.
- par contre pour les zones haut/droite et bas/gauche ça ne fonctionne pas
et je ne comprends pas pourquoi

Est-ce que vous auriez une idée sur l'origine de ce comportement ?
Je cherche juste une explication car j'ai procédé autrement finalement.

seb



le code:

_root.test.onPress = function (){
this.x0 = _root._xmouse;
this.y0 = _root._ymouse;
_root.test._x = this.x0;
_root.test._y = this.y0;
_root.test.onEnterFrame = function () {
var x1 = _root._xmouse - this.x0;
var y1 = _root._ymouse - this.y0;
var rotation = 0;
var tmp = 0;
if(x1 < 0 && y1 < 0) {
x1 = -x1;
y1 = -y1;
rotation = 180;
} else if(x1 < 0 && y1 > 0) {
tmp = y1;
y1 = -x1;
x1 = tmp;
rotation = 90;
} else if(x1 > 0 && y1 < 0) {
tmp = y1;
y1 = x1;
x1 = -tmp;
rotation = -90;
}
_root.test._width = x1;
_root.test._height = y1;
_root.test._rotation = rotation;
}
}
_root.test.onRelease = _root.test.onReleaseOutside = function () {
delete _root.test.onEnterFrame;
}
stop();

2 réponses

Avatar
ekameleon
Hello :)

1 - Déjà pour commencer pourquoi tu mets des _root partout ? Si tu codes
sur la timeline principale évite !! _root c'est mal lol

Le jour où tu charges ton animation dans une autre tu vas avoir des
problèmes... pense à utiliser le fait que ton clip est en local pour
l'appeller simplement par son nom :)


2 - Quand tu es dans une fonction qui appartient à un clip ou n'importe
quel objet... pas besoin de rappeler cet objet avec son url absolue !!
Tu tapes à chaque fois _root.test alors qu'un simple this suffit :)

Petite correction rapide pour un code + propre :

[code]
test.onPress = function (){
var x0 = _root._xmouse ;
var y0 = _root._ymouse ;
this._x = x0 ;
this._y = y0 ;
this.onEnterFrame = function () {
var x1 = _root._xmouse - x0 ;
var y1 = _root._ymouse - y0 ;
trace("> " + x1 + " / " + y1) ;
var rotation = 0 ;
var tmp = 0;
if(x1 < 0 && y1 < 0) {
x1 *= -1 ;
y1 *= -1 ;
rotation = 180 ;
} else if (x1 < 0 && y1 > 0) {
tmp = y1 ;
y1 = -x1 ;
x1 = tmp ;
rotation = 90 ;
} else if(x1 > 0 && y1 < 0) {
tmp = y1;
y1 = x1;
x1 = -tmp;
rotation = -90;
}
this._width = x1;
this._height = y1;
this._rotation = rotation ;
}
}
test.onRelease = test.onReleaseOutside = function () {
delete this.onEnterFrame;
}

[/code]

Bon maintenant tu cherches à faire quoi exactement avec ton clip ? car
je vois qu'il y a un problème de symétrie mais faudrait que tu sois un
peu + explicite à mon avis :)

eKA+ :)



le code:

_root.test.onPress = function (){
this.x0 = _root._xmouse;
this.y0 = _root._ymouse;
_root.test._x = this.x0;
_root.test._y = this.y0;
_root.test.onEnterFrame = function () {
var x1 = _root._xmouse - this.x0;
var y1 = _root._ymouse - this.y0;
var rotation = 0;
var tmp = 0;
if(x1 < 0 && y1 < 0) {
x1 = -x1;
y1 = -y1;
rotation = 180;
} else if(x1 < 0 && y1 > 0) {
tmp = y1;
y1 = -x1;
x1 = tmp;
rotation = 90;
} else if(x1 > 0 && y1 < 0) {
tmp = y1;
y1 = x1;
x1 = -tmp;
rotation = -90;
}
_root.test._width = x1;
_root.test._height = y1;
_root.test._rotation = rotation;
}
}
_root.test.onRelease = _root.test.onReleaseOutside = function () {
delete _root.test.onEnterFrame;
}
stop();




Avatar
seb
"ekameleon" a écrit dans le message de news:
e54loi$gfd$
Hello :)



Hola

Bon maintenant tu cherches à faire quoi exactement avec ton clip ?



Je veux juste qu'il s'étende en suivant la souris (onPress) et il ne le fait
pas correctement dans 2 zones ( quand on déplace la souris vers haut/droite
et vers bas/gauche).

Si on rajoute un trace(this._width+"/"+ x1) juste en dessous à la fin du
onEnterFrame() on s'aperçoit que les valeurs ne sont pas égales alors qu'on
vient tout juste d'affecter x1 à this._width


test.onPress = function (){
var x0 = _root._xmouse ;
var y0 = _root._ymouse ;
this._x = x0 ;
this._y = y0 ;
this.onEnterFrame = function () {
var x1 = _root._xmouse - x0 ;
var y1 = _root._ymouse - y0 ;
var rotation = 0 ;
var tmp = 0;
if(x1 < 0 && y1 < 0) {
x1 *= -1 ;
y1 *= -1 ;
rotation = 180 ;
} else if (x1 < 0 && y1 > 0) {
tmp = y1 ;
y1 = -x1 ;
x1 = tmp ;
rotation = 90 ;
} else if(x1 > 0 && y1 < 0) {
tmp = y1;
y1 = x1;
x1 = -tmp;
rotation = -90;
}
this._width = x1;
trace(this._width+"/"+ x1); // <=== on obtient pas les mêmes valeurs: mais
pourquoi ?
this._height = y1;
this._rotation = rotation ;
}
}
test.onRelease = test.onReleaseOutside = function () {
delete this.onEnterFrame;
}