IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ActionScript 1 & ActionScript 2 Discussion :

onEnterFrame et passage d'arguments


Sujet :

ActionScript 1 & ActionScript 2

  1. #1
    FMC
    FMC est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2005
    Messages : 25
    Par défaut onEnterFrame et passage d'arguments
    Bonjour,

    je souhaite automatiser mes effets, à commencer par le fadeIn/Out directionnel sur les MovieClip.

    Pour des raisons de compatibilité, il faut que cela soit en AS2 et Flash 7. Voici le code que j'ai pondu :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    function eAlpha(obj, duree, dist, dir, arrives) {
     
    	distStep = (dist/duree);
     
    	if (arrives) {
    		alph = 0;
    		alphTo = 100;
    	} else {
    		alph = 100;
    		alphTo = 0;
    	}
    	alphStep = Math.round((alphTo-alph)/duree);
     
    	if (arrives) {
    		toX = obj._x;
    		toY = obj._y;
    	} else {
    		fromX = obj._x;
    		fromY = obj._y;
    	}
     
    	switch (dir) {
    		case "H" :
    		case "T" :
    			if (arrives) {
    				fromY = toY-dist;
    				fromX = toX;
    				toI = distStep;
    			} else {
    				toX = fromX;
    				toY = fromY-dist;
    				toI = -distStep;
    			}
    			break;
     
    		case "D" :
    		case "R" :
    			if (arrives) {
    				fromY = toY;
    				fromX = toX+dist;
    				toI = -distStep;
    			} else {
    				toX = fromX+dist;
    				toY = fromY;
    				toI = distStep;
    			}
    			break;
     
    		case "B" :
    			if (arrives) {
    				fromY = toY+dist;
    				fromX = toX;
    				toI = -distStep;
    			} else {
    				toX = fromX;
    				toY = fromY+dist;
    				toI = distStep;
    			}
    			break;
     
    		case "L" :
    		case "G" :
    			if (arrives) {
    				fromY = toY;
    				fromX = toX-dist;
    				toI = distStep;
    				break;
    			} else {
    				toX = fromX-dist;
    				toY = fromY;
    				toI = -distStep;
    			}
    		default :
    			fromX = obj._x;
    			fromY = obj._y;
    			toX = obj._x;
    			toY = obj._y;
    			break;
    	}
    	obj._alpha = alph;
    	obj._x = fromX;
    	obj._y = fromY;
    	frameLeft = duree;
     
    	obj.onEnterFrame = function() {
     
    		if (this._alpha+alphStep<>alphTo) {
    			this._alpha = this._alpha+alphStep;
    		} else {
    			this._alpha = alphTo;
    		}
    		if (fromX<>toX && this._x<>toX) {
    			this._x = this._x+toI;
    		}
    		if (fromY<>toY && this._y<>toY) {
    			this._y = this._y+toI;
    		}
    		if (frameLeft--<=0) {
    			delete this.onEnterFrame;
    		}
     
    	};
    }
    Et sur le clip en question j'ai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    onClipEvent(load) {
    	_parent.eAlpha(this, 25, 30, "L", true);
    }
    Ca fonctionne très bien tant que je n'utilise pas la fonction eAlpha simultanément sur plusieurs clips. Si je le fais, il y a partage de variables, or je ne comprends pas très bien pourquoi.

    Par exemple, frameLeft est partagée, ce qui cause la fin de l'effet avant qu'il ne soit complété.

    Merci de m'éclairer !

  2. #2
    FMC
    FMC est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2005
    Messages : 25
    Par défaut
    J'ai trouvé, il suffisait de définir mes variables directement dans mon objet (obj).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    function eAlpha(obj, duree, dist, dir, arrives) {
     
    	obj.duree = duree
    	obj.dist = dist
    	obj.dir = dir
    	obj.arrives = arrives
    	obj.distStep = (obj.dist/obj.duree);
     
    	if (obj.arrives) {
    		obj.alph = 0;
    		obj.alphTo = 100;
    	} else {
    		obj.alph = 100;
    		obj.alphTo = 0;
    	}
    	obj.alphStep = Math.round((obj.alphTo-obj.alph)/obj.duree);
     
    	if (obj.arrives) {
    		obj.toX = obj._x;
    		obj.toY = obj._y;
    	} else {
    		obj.fromX = obj._x;
    		obj.fromY = obj._y;
    	}
     
    	switch (obj.dir) {
    		case "H" :
    		case "T" :
    			if (obj.arrives) {
    				obj.fromY = obj.toY-obj.dist;
    				obj.fromX = obj.toX;
    				obj.toI = obj.distStep;
    			} else {
    				obj.toX = obj.fromX;
    				obj.toY = obj.fromY-obj.dist;
    				obj.toI = -obj.distStep;
    			}
    			break;
     
    		case "D" :
    		case "R" :
    			if (obj.arrives) {
    				obj.fromY = obj.toY;
    				obj.fromX = obj.toX+obj.dist;
    				obj.toI = -obj.distStep;
    			} else {
    				obj.toX = obj.fromX+obj.dist;
    				obj.toY = obj.fromY;
    				obj.toI = obj.distStep;
    			}
    			break;
     
    		case "B" :
    			if (obj.arrives) {
    				obj.fromY = obj.toY+obj.dist;
    				obj.fromX = obj.toX;
    				obj.toI = -obj.distStep;
    			} else {
    				obj.toX = obj.fromX;
    				obj.toY = obj.fromY+obj.dist;
    				obj.toI = obj.distStep;
    			}
    			break;
     
    		case "L" :
    		case "G" :
    			if (obj.arrives) {
    				obj.fromY = obj.toY;
    				obj.fromX = obj.toX-obj.dist;
    				obj.toI = obj.distStep;
    				break;
    			} else {
    				obj.toX = obj.fromX-obj.dist;
    				obj.toY = obj.fromY;
    				obj.toI = -obj.distStep;
    			}
    		default :
    			obj.fromX = obj._x;
    			obj.fromY = obj._y;
    			obj.toX = obj._x;
    			obj.toY = obj._y;
    			break;
    	}
    	obj._alpha = obj.alph;
    	obj._x = obj.fromX;
    	obj._y = obj.fromY;
    	obj.frameLeft = obj.duree;
     
    	obj.onEnterFrame = function() {
     
    		this.frameLeft--;
     
    		if (this._alpha+this.alphStep<>this.alphTo) {
    			this._alpha = this._alpha+this.alphStep;
    		} else {
    			this._alpha = this.alphTo;
    		}
    		if (this.fromX<>this.toX && this._x<>this.toX) {
    			this._x = this._x+this.toI;
    		}
    		if (this.fromY<>this.toY && this._y<>this.toY) {
    			this._y = this._y+this.toI;
    		}
     
    		if (this.frameLeft<=0) {
    			delete this.onEnterFrame;
    		}
     
    	};
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. passage d'argument sur l'imprimante
    Par linux dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 07/10/2005, 16h25
  2. [JAVASCRIPT] passage d'argument à une fonction
    Par LE NEINDRE dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 03/06/2005, 18h17
  3. [TASM] Passage d'argument à une macro
    Par sorry60 dans le forum Assembleur
    Réponses: 13
    Dernier message: 23/04/2005, 18h22
  4. [web] passage d'arguments à un CGI
    Par ma2th dans le forum Web
    Réponses: 4
    Dernier message: 20/08/2004, 12h18
  5. passage d'argument à la procédure main ()
    Par Zazeglu dans le forum C
    Réponses: 5
    Dernier message: 01/09/2003, 19h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo