Bonjour, j'ai suivi les tutos et exemples le plus fidèlement possible et pourtant je n'arrive pas à faire marcher le drag & drop
Pour l'instant je ne fais que des "trace" mais rien ne s'affiche. J'ai bien le drag qui démarre, mais impossible d'accepter le drop
Pouvez vous m'aider?
ModuleGardenEditor.mxml
GardenItemsPanel.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:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="1000" height="800" xmlns:gardeneditor="gardeneditor.*" backgroundColor="0x888888" backgroundAlpha="0.1" contentCreationComplete="contentCreationCompleteHandler(event)"> <s:layout> <s:HorizontalLayout/> </s:layout> <fx:Declarations> <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.core.DragSource; import mx.events.DragEvent; import mx.managers.DragManager; protected function contentCreationCompleteHandler(event:Event):void { var gardenItem:GardenItem = null; for(var i:int=0;i<gardenItemsPanel.numChildren;i++){ gardenItem = gardenItemsPanel.getChildAt(i) as GardenItem; gardenItem.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler); } } protected function mouseMoveHandler(event:MouseEvent):void{ var dragInitiator:GardenItem = GardenItem(event.currentTarget); var dragSource:DragSource = new DragSource; dragSource.addData(dragInitiator,"GardenItem"); DragManager.doDrag(dragInitiator, dragSource, event); } protected function gardenPlan_dragEnterHandler(event:DragEvent):void { trace("enter"); DragManager.acceptDragDrop(GardenPlan(event.currentTarget)); } protected function gardenPlan_dragDropHandler(event:DragEvent):void { trace("drop"); } ]]> </fx:Script> <s:SkinnableContainer backgroundColor="0x888888" backgroundAlpha="0.5" width="128" height="100%"> <s:layout> <s:VerticalLayout/> </s:layout> <s:Label text="Glissez les objets çi dessous sur le plan" width="100" textAlign="center"/> <gardeneditor:GardenItemsPanel id="gardenItemsPanel"/> </s:SkinnableContainer> <s:SkinnableContainer backgroundColor="0xffffff" backgroundAlpha="1" width="80%" height="100%"> <gardeneditor:GardenPlan id="gardenPlan" dragEnter="gardenPlan_dragEnterHandler(event)" dragDrop="gardenPlan_dragDropHandler(event)"/> </s:SkinnableContainer> </s:Module>
GardenItem.mxml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="utf-8"?> <s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:gardeneditor="gardeneditor.*" horizontalCenter="0"> <fx:Declarations> <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). --> </fx:Declarations> <gardeneditor:GardenItem backgroundImg="@Embed(source='../assets/arbre.png')" /> <gardeneditor:GardenItem backgroundImg="@Embed(source='../assets/arbre.png')" /> <gardeneditor:GardenItem backgroundImg="@Embed(source='../assets/arbre.png')" /> </s:VGroup>
GardenPlan.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 <?xml version="1.0" encoding="utf-8"?> <s:SkinnableContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="96" height="96"> <fx:Declarations> <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). --> </fx:Declarations> <fx:Script> <![CDATA[ [Bindable] public var backgroundImg:Object; ]]> </fx:Script> <s:Rect left="0" right="0" top="0" bottom="0"> <s:fill> <s:BitmapFill source="{backgroundImg}"/> </s:fill> </s:Rect> </s:SkinnableContainer>
Merci!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:Declarations> <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). --> </fx:Declarations> </s:Group>
Partager