Tout est là ... :
menuDeroulant.mxmlCODE
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="214" height="125" xmlns:option="*" backgroundColor="#ECECEC" creationComplete="initialisation();" xmlns="*" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.containers.VBox;
include "commun.as"
import mx.controls.Label;
import mx.core.UIComponent;
import flash.geom.*
import flash.display.*
import mx.controls.Image;
public var _pointille:Boolean = new Boolean();
public var _titre:String = new String();
public var _nbresultat:Number = new Number();
private var puce:Image = new Image();
private var titreMenu:Label = new Label();
private var lignePointille:UIComponent = new UIComponent();
private var carrePointille:UIComponent = new UIComponent();
private var dbFondTitre:UIComponent = new UIComponent();
private var fondTitre:UIComponent = new UIComponent();
private var ligneTitre:UIComponent = new UIComponent();
private var conteneurOptions:VBox = new VBox();
[Embed(source='img/puceMenuDeroulant.png')] private var puceTitre:Class;
private function initialisation():void {
dbFondTitre.graphics.beginFill(0xE78787, 1);
dbFondTitre.graphics.drawRect(0, 0, 214, 22);
dbFondTitre.graphics.endFill();
this.addChild(dbFondTitre);
matrice.createGradientBox(20, 20, 0, 0, 0);
fondTitre.graphics.beginGradientFill(fillType, colors, alphas, ratios, matrice, spreadMethod);
fondTitre.graphics.drawRect(0, 0, 20, 212);
fondTitre.graphics.endFill();
this.addChild(fondTitre);
if (_pointille) {
createPointLine(1, 1, 3, 0);
this.addChild(lignePointille);
}
ligneTitre.graphics.beginFill(0xA5A5A5, 1);
ligneTitre.graphics.drawRect(0, 0, 214, 1);
ligneTitre.graphics.endFill();
this.addChild(ligneTitre);
puce.source = puceTitre;
this.addChild(puce);
this.addChild(titreMenu);
this.addChild(conteneurOptions);
for (var i:Number = 0; i < 10; i++) {
var option:optionMenu = new optionMenu();
option.id = "option" + i;
option._valueTxt = "Option" + i;
conteneurOptions.addChild(option);
}
positionElement();
enterData();
}
private function positionElement():void {
dbFondTitre.x = 0;
dbFondTitre.y = 1;
fondTitre.rotation = -90;
fondTitre.x = 1;
fondTitre.y = 22;
titreMenu.x = 21;
titreMenu.y = 0;
puce.x = 7;
puce.y = 9;
ligneTitre.x = 0;
ligneTitre.y = 23;
conteneurOptions.y = 26;
conteneurOptions.height = 99;
conteneurOptions.width = 214;
}
private function enterData():void {
titreMenu.htmlText = "<font color='#FFFFFF' size='14'>" + _titre + "</font>";
}
private function createPointLine(largeur:Number, hauteur:Number, espaceLargeur:Number, espaceHauteur:Number):void {
for (var j:Number = 0; j < (this.width / espaceLargeur); j++) {
lignePointille.graphics.beginFill(0x404040, 1)
lignePointille.graphics.drawRect(j * espaceLargeur, j * espaceHauteur, largeur, hauteur);
lignePointille.graphics.endFill();
}
}
]]>
</mx:Script>
</mx:Canvas>
optionMenu.mxmlCODE
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="197" height="18" creationComplete="createElement();">
<mx:Script>
<![CDATA[
import flash.text.TextFormat;
import flash.text.TextField;
import mx.controls.Image;
import mx.controls.Label;
import mx.core.UIComponent;
import mx.effects.Tween;
import mx.effects.TweenEffect;
import mx.effects.easing.*;
public var _valueTxt:String = new String();
private var actif:Boolean = new Boolean();
private var cocheOption:Image = new Image();
private var libelle:Label = new Label();
private var formatSelect:TextFormat = new TextFormat();
private var fondGris:UIComponent = new UIComponent();
private var globalButton:UIComponent = new UIComponent();
private var carreRouge:UIComponent = new UIComponent();
[Embed(source='img/coche.png')] private var cocheEmbed:Class;
[Embed(source='img/coche_gris.png')] private var cocheGrisEmbed:Class;
private function createElement():void {
formatSelect.color = 0xFFFFFF;
fondGris.graphics.beginFill(0x737373, 1);
fondGris.graphics.drawRect(0, 0, 197, 18);
fondGris.graphics.endFill();
addChild(fondGris);
carreRouge.graphics.lineStyle(1, 0xcc0000, 1);
carreRouge.graphics.drawRect(8, 5, 8, 8);
addChild(carreRouge);
cocheOption.source = cocheGrisEmbed;
cocheOption.x = 8;
cocheOption.y = 4;
addChild(cocheOption);
libelle.x = 25;
libelle.y = -1;
libelle.selectable = false;
addChild(libelle);
globalButton.graphics.beginFill(0x737373, 0);
globalButton.graphics.drawRect(0, 0, 197, 18);
globalButton.graphics.endFill();
globalButton.addEventListener(MouseEvent.MOUSE_OVER, actionMouse);
globalButton.addEventListener(MouseEvent.MOUSE_OUT, actionMouse);
globalButton.addEventListener(MouseEvent.CLICK, actionMouse);
globalButton.buttonMode = true;
addChild(globalButton);
initialisation();
}
private function initialisation():void {
actif = false;
fondGris.alpha = 0;
cocheOption.alpha = 0;
libelle.htmlText = _valueTxt;
}
private function actionMouse(event:MouseEvent):void {
switch(event.type) {
case "mouseOver" :
if (actif) { cocheOption.alpha = 0; } else if (!actif) { cocheOption.alpha = 1; }
break;
case "mouseOut" :
if (actif) { cocheOption.alpha = 1; } else if (!actif) { cocheOption.alpha = 0; }
break;
case "click" :
var animationFondOut:Tween;
if (actif ) {
actif = false;
animationFondOut = new Tween(fondGris, fondGris.alpha, 0, 500);
animationFondOut.easingFunction = Back.easeIn;
animationFondOut.setTweenHandlers(updateAlpha, endClick);
} else if (!actif) {
actif = true;
animationFondOut = new Tween(fondGris, fondGris.alpha, 1, 500);
animationFondOut.easingFunction = Back.easeIn;
animationFondOut.setTweenHandlers(updateAlpha, endClick);
}
break;
}
}
private function updateAlpha(val:Object):void { fondGris.alpha = Number(val); }
private function endClick (val:Object):void {
if (actif) {
cocheOption.source = cocheEmbed;
carreRouge.alpha = 0;
libelle.htmlText = "<font color='#FFFFFF'>" + _valueTxt + "</font>";
libelle.x = 36;
} else if (!actif) {
cocheOption.source = cocheGrisEmbed;
carreRouge.alpha = 1;
libelle.htmlText = _valueTxt;
libelle.x = 25;
}
}
]]>
</mx:Script>
</mx:Canvas>