Thank you Jae. That is far better than what I had worked out.

This had led me to another question. When I move one of the buttons, 
the mouseUp function is firing and going to the correct IF statement. 
What it isn't doing is moving the item to the (x,y) position 
specified in the IF statement, it's just dropping it where ever I 
drop it.

I'm also curious what the impact is of having every item 
called "buttonA" and if there isn't a better way.


<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
layout="absolute" width="500" height="620" borderStyle="solid" 
creationComplete="initApp();">

<mx:Script>
        <![CDATA[
                        public var slot001A:Boolean;
                        public var slot001B:Boolean;            
        

                        import mx.controls.Button;
                        import mx.controls.Alert;
            import mx.events.DragEvent;
            import mx.controls.List;
            import mx.managers.DragManager;
            import mx.core.DragSource;
                        
            private function initApp():void {
                var dp:Array = ([
                    {label:"First", data:"25"},
                    {label:"Second", data:"50"},
                    {label:"Third", data:"75"},
                    {label:"Fourth", data:"100"},
                ]);
                listOne.dataProvider = dp;
            }
            
            private function dragEnterHandler(event:DragEvent):void {
                var dropTarget:Canvas=event.currentTarget as Canvas;
                    dropTarget.setStyle("borderThickness", 5);
               if (slot001A==false) {
                                        if (event.stageY.valueOf() >= 
10 && event.stageY.valueOf() < 110) {
                        DragManager.acceptDragDrop(dropTarget); 
                                        
                                        }
               }
               if (slot001B==false) {
                                        if (event.stageY.valueOf() >= 
110 && event.stageY.valueOf() < 210) {
                        DragManager.acceptDragDrop(dropTarget); 
                                        
                                        }
               }
            }
                
            private function dragExitHandler(event:DragEvent):void {
                var dropTarget:Canvas=event.currentTarget as Canvas;
                                revertBoxBorder();                
            }
            
            public function dragDropHandler(event:DragEvent):void {
                var dropTarget:Canvas=event.currentTarget as Canvas;
                var buttonA:Button = new Button;
                                
        buttonA.label=listOne.selectedItem.label;
                                
        buttonA.height=listOne.selectedItem.data;
                                        buttonA.addEventListener
(MouseEvent.MOUSE_DOWN, mouseDown);
                                        buttonA.addEventListener
(MouseEvent.MOUSE_MOVE, mouseMove);
                                        buttonA.addEventListener
(MouseEvent.MOUSE_UP, mouseUp);
                                        buttonA.addEventListener
(MouseEvent.CLICK, buttonClick);

                                if (event.stageY.valueOf() >= 10 && 
event.stageY.valueOf() < 110) {
                                        buttonA.x = 0;
                                        buttonA.y = 0;
                                        buttonA.width = 150;
                                        slot001A=true;
                                }
                                else{
                                        if (event.stageY.valueOf() >= 
110 && event.stageY.valueOf() < 200) {
                                                buttonA.x = 0;
                                                buttonA.y = 110;
                                                buttonA.width = 150;
                                                slot001B=true;
                                        }
                                }
                                dropBox.addChild(buttonA);
                revertBoxBorder();                
            }
                        
            public function buttonClick(event:MouseEvent):void {

            }

                        public function mouseMove
(event:MouseEvent):void {
                                event.updateAfterEvent();
                        }

                        public function mouseDown
(event:MouseEvent):void {
                                if (event.target is Button) {
                                        event.target.startDrag();
                                }
                        }
                        
                        public function mouseUp
(event:MouseEvent):void {
                var buttonA:Button = new Button;
                                if (event.target is Button) {
                                        event.target.stopDrag();
                                        if (event.stageY.valueOf() >= 
10 && event.stageY.valueOf() < 110) {
                                                buttonA.x = 0;
                                                buttonA.y = 0;
                                                buttonA.width = 150
        
                                        }
                                        if (event.stageY.valueOf() >= 
110 && event.stageY.valueOf() < 210) {
                                                buttonA.x = 0;
                                                buttonA.y = 100;
                        
                                                buttonA.width = 150
                                        }
                                }
                        }                           
            private function revertBoxBorder():void {
                dropBox.setStyle("borderThickness", 
1);                
            } 
            
        ]]>
</mx:Script>
                <mx:List id="listOne" dragEnabled="true" 
dropEnabled="true" x="10" y="10"></mx:List>
                <mx:Canvas x="190" y="10" width="308" height="200" 
borderStyle="solid" borderColor="#000000" backgroundColor="#FFFFFF" 
                        dragEnter="dragEnterHandler(event);" 
id="dropBox" dragExit="dragExitHandler(event);"
                        dragDrop="dragDropHandler(event);">     
                </mx:Canvas>
</mx:Application>

Reply via email to