Bonjour,
l'idée est d'avoir une page principale (Main.mxml), laquelle possède un bouton (mainBouton) dans une barre d'outils en haut.
- mainBouton déclenche l'ouverture d'une TitleWindow (Window1), Window1 qui possède un bouton (w1Bouton).
- w1Bouton déclenche l'ouverture d'une seconde TitleWindow (Window2)
- et désactive (enabled=false) mainBouton : pas de soucis (mais ma solution ne doit pas être la bonne, voir ci-dessous)
Une fois sur Window2,
- le but est de réactiver mainBouton lorsque l'on ferme Window2 : et là, je n'y arrive pas...
Mon dernier essai infructueux étant dans Window1 onFermetureEcran() avec this.dispatchEvent(new MyEvent(MyEvent.BOUTON_ACTIF_OU_NON,true))
Une idée, un conseil, un barbecue, une sortie ski, je suis ouvert à toute proposition.
Merci d'avance.
Le code complet pour tester (elle est pas belle la vie!!). Au passage, vous noterez la redondance du code (afficherEcran(), onFermetureEcran()...) : c'est secondaire mais là aussi, un conseil sera bienvenu. Vous l'aurez deviné j'en suis aux balbutiements de flex/as.
Main.mxml
Window1.mxml
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 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" minWidth="955" minHeight="600" applicationComplete="initialiserHeader()"> <fx:Declarations> <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.events.CloseEvent; import mx.managers.PopUpManager; import spark.components.TitleWindow; private function initialiserHeader():void{ this.addEventListener(MyEvent.BOUTON_ACTIF_OU_NON,activerBoutonsHeader); } private function activerBoutonsHeader(event:MyEvent):void{ mainBouton.enabled = event.isActif; } private function afficherEcran(quelEcran:Class, event:MouseEvent):void { var monEcran:TitleWindow = new quelEcran(); monEcran.width = 500; monEcran.height = 400; monEcran.addEventListener(CloseEvent.CLOSE, onFermetureEcran); PopUpManager.addPopUp(monEcran, this); PopUpManager.centerPopUp(monEcran); monEcran = null; this.dispatchEvent(new MyEvent(MyEvent.BOUTON_ACTIF_OU_NON,false)); } private function onFermetureEcran(event:CloseEvent):void { var quelEcran:TitleWindow = event.target as TitleWindow; fermerEcran(quelEcran); quelEcran = null; } private function fermerEcran(quelEcran:TitleWindow):void { PopUpManager.removePopUp(quelEcran); quelEcran = null; } ]]> </fx:Script> <s:HGroup height="50" gap="0"> <s:Group> <s:Label text="Salut" y="5" fontWeight="bold" fontSize="15" /> <s:Label text="Les Dev" y="20" color="#EC4353" fontSize="12" fontWeight="bold" /> </s:Group> <s:Button id="mainBouton" height="100%" label="Window1" click="afficherEcran(Window1, event)"/> </s:HGroup> <s:Label y="70" width="797" height="182" fontSize="36" fontWeight="bold" text="Ecran Main" textAlign="center" verticalAlign="middle"/> </s:Application>
Window2.mxml
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 <?xml version="1.0" encoding="utf-8"?> <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" width="400" height="300" minHeight="100" minWidth="150" contentCreationComplete="definirEcran()" > <fx:Script> <![CDATA[ import mx.events.CloseEvent; import mx.managers.PopUpManager; private function definirEcran():void { this.title = "Window1"; this.closeButton.visible = false; } private function afficherEcran(quelEcran:Class, event:MouseEvent):void { var monEcran:TitleWindow = new quelEcran(); monEcran.width = 500; monEcran.height = 400; monEcran.addEventListener(CloseEvent.CLOSE, onFermetureEcran); PopUpManager.addPopUp(monEcran, this); PopUpManager.centerPopUp(monEcran); monEcran = null; } private function onFermetureEcran(event:CloseEvent):void { var quelEcran:TitleWindow = event.target as TitleWindow; fermerEcran(quelEcran); quelEcran = null; this.dispatchEvent(new MyEvent(MyEvent.BOUTON_ACTIF_OU_NON,true)); } private function fermerEcran(quelEcran:TitleWindow):void { PopUpManager.removePopUp(quelEcran); quelEcran = null; } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Scroller width="100%" height="100%"> <s:VGroup horizontalAlign="center" verticalAlign="middle"> <s:Label text="{title}" fontSize="45" fontWeight="bold" color="0x404040" /> <s:Button id="w1Bouton" label="Afficher Window2" click="dispatchEvent(new CloseEvent(CloseEvent.CLOSE,true));afficherEcran(Window2, event)"/> </s:VGroup> </s:Scroller> </s:TitleWindow>
MyEvent.as
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 <?xml version="1.0" encoding="utf-8"?> <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" width="400" height="300" minHeight="100" minWidth="150" contentCreationComplete="definirEcran()" > <fx:Script> <![CDATA[ private function definirEcran():void { this.title = "Window2"; this.closeButton.visible = true; } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Scroller width="100%" height="100%"> <s:VGroup horizontalAlign="center" verticalAlign="middle"> <s:Label text="{title}" fontSize="45" fontWeight="bold" color="0x404040" /> </s:VGroup> </s:Scroller> </s:TitleWindow>
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 package { import flash.events.Event; public class MyEvent extends Event { public var isActif:Boolean=false; public var eventType:String=""; public static const BOUTON_ACTIF_OU_NON:String="activationMainBouton"; public function MyEvent(type:String, isActif:Boolean) { super(type, true, true); this.isActif = isActif; this.eventType = type; } } }
Partager