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
|
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
class ButtonTool extends Sprite {
public function new(onClick){
super();
var b = new MovieClip();
b.graphics.lineStyle(2,0xCC7700);
b.graphics.beginFill(0xFF9900);
b.graphics.drawRoundRect(0,0,24,24,100,100);
var sb = new flash.display.SimpleButton();
sb.upState = b;
sb.overState = b;
sb.downState = b;
sb.hitTestState = b;
sb.useHandCursor = true;
sb.addEventListener(flash.events.MouseEvent.MOUSE_UP, function(e){onClick(); });
this.addChild(sb);
}
}
class Bulle extends Sprite {
static var deplace : Bool = false;
public function new(){
super();
var b2 = new Sprite();
b2.graphics.lineStyle(2,0x00FF00);
b2.graphics.beginFill(0x0000FF);
b2.graphics.drawRoundRect(100,100,10,10,100,100);
b2.addEventListener(flash.events.MouseEvent.MOUSE_OVER,donneFocus);
b2.addEventListener(flash.events.MouseEvent.MOUSE_OUT ,lacheFocus);
b2.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,startMove);
this.addChild(b2);
flash.Lib.current.stage.addEventListener(MouseEvent.MOUSE_MOVE, deplaceBulle);
}
public function startMove(event:MouseEvent){
deplace=true;
}
public function deplaceBulle(event:MouseEvent){
if(!event.buttonDown){
deplace=false;
}
if (deplace==true){
var mouse_x : Float = event.stageX;
var mouse_y : Float = event.stageY;
var margesx=this.width/1.5;
var margesy=this.height/1.5;
this.x = mouse_x;
this.y = mouse_y;
}
}
public function donneFocus(event:MouseEvent) {
this.filters = [new GlowFilter(0xFF0000,0.5, 8, 8, 20, 1, false, false) ];
this.alpha = 1;
}
public function lacheFocus(event:MouseEvent) {
this.filters = [new GlowFilter(0xFF0000,0, 8, 8, 20, 1, false, false) ];
this.alpha = 0.3;
}
}
class Main {
static var bubArray = new Array<Sprite>();
static var butTool = new Array<Sprite>();
static var compteurBulles : Int = 0; //index de la dernière bulle créée
static var bulle : Dynamic;
public static var bulle_mc : Sprite;
public static function main () {
butTool[0] = new ButtonTool(function(){bubArray[compteurBulles]=new Bulle();flash.Lib.current.stage.addChild(bubArray[compteurBulles]);compteurBulles++;});
flash.Lib.current.stage.addChild (butTool[0]);
}
} |
Partager