Bonjour
J'ai crée une classe bouton (le code ci dessous) dans laquelle les évenemnts "onRollOver et onRollOut" sont associés.
A partir d'une autre classe (Main) j'intance 3 boutons de cette classe.
Apres compile (FlashDevelop) le dessin de chaque bouton est correcte mais l'évenement ne se réalise que sur le dernier bouton.
Je débute en AS2 , où est l'erreur?
Merci pour votre aide
Bilou76
la classe Bouton
================================================
class Bouton{
private var x:Number;
private var y:Number;
function Bouton ( posx:Number,posy:Number) {
_root.x = posx;
_root.y = posy;
}
function addBouton(){
var niveau:Number = _root.getNextHighestDepth();
var mc = _root.createEmptyMovieClip( "bouton" + niveau , niveau);
with (mc){
beginFill (0x0000FF,100);
lineStyle (3,0xFF00FF,50);
moveTo( x, y );
lineTo (x + 100, y);
lineTo (x + 100, y + 50);
lineTo (x + 0, y + 50);
lineTo (x + 0, y + 0);
endFill();
}
mc.onRollOver = function() {
with (mc){
beginFill (0x440000,100);
moveTo( x, y );
lineTo (x + 100, y);
lineTo (x + 100, y + 50);
lineTo (x + 0, y + 50);
lineTo (x + 0, y + 0);
endFill();
}
}
mc.onRollOut = function() {
with (mc){
beginFill (0x0000FF,100);
moveTo( x, y );
lineTo (x + 100, y);
lineTo (x + 100, y + 50);
lineTo (x + 0, y + 50);
lineTo (x + 0, y + 0);
endFill();
}
}
}
}
la classe principale
========================================
import Bouton;
class DesBoutons{
static function main()
{
var bt : Bouton;
bt = new Bouton(10 , 10);
bt.addBouton();
var bt2 : Bouton;
bt2 = new Bouton(100,100);
bt2.addBouton();
var bt3 : Bouton;
bt3 = new Bouton(200,200);
bt3.addBouton();
}
}
Partager