Hmm, very strange. I wonder if it is because my list box is being
created by a repeater. Or becaue drag is enabled on it? here's my code...


<?xml version="1.0" encoding="utf-8"?>
<mx:VBox 
        xmlns:mx="http://www.macromedia.com/2003/mxml";
        xmlns:ppcView="com.ppc.stickies.view.*"
        width="720" 
        height="590" 
        backgroundColor="#666666" 
        cornerRadius="24"
        marginBottom="8"  marginTop="8"  marginLeft="8"  marginRight="8">
        
        <ppcView:ProjectAssignmentsViewHelper
name="projectAssignmentsViewHelper" view="{ this }" />
        
        <!--
============================================================================================
-->
        
        <mx:Script>
        <![CDATA[
                import com.iterationtwo.cairngorm.view.ViewLocator;
                import com.iterationtwo.cairngorm.control.EventBroadcaster;
        import mx.managers.DragManager;
        import mx.core.DragSource;
                
        
//-----------------------------------------------------------------------------------
                //Page variables
                var oPersonnel:Object;
                var aProjects : Array = new Array();
                var numPersonnelID : String;
                
        
//-----------------------------------------------------------------------------------
                //Drag and Drop Functions
                private function doDragEnter(event)     {
                        event.handled="true";
                }
                
                //-------------------------------------
                private function doDragExit(event) {
                        event.target.hideDropFeedback();
                }
                
                //-------------------------------------
                private function doDragOver(event) {
                        event.target.showDropFeedback();
                
                        if (Key.isDown(Key.CONTROL))
                                event.action = DragManager.COPY;
                        else
                                event.action = DragManager.MOVE;
                }
                
                //-------------------------------------
                private function doDragDrop(event) {
                
                        doDragExit(event);
                        var items = event.dragSource.dataForFormat("items");
                        var dest = event.target;
                        var dropLoc = dest.getDropLocation()
                        var itemExists:String = "0";
                        
                        if (dropLoc.id == trash){
                                mx.core.Application.alert('TRASH');
                        }
                
//mx.core.Application.alert(event.target.dataProvider[0].TXTPROJECTNAME
+' '+ items.length );
                        
                        items.reverse()
                
                        for(var i = 0; i < items.length; i++) {
                                //This code checks if the item already exists 
in the list before
adding.
                                //And checks to see if the drag is coming from 
the project list.
If the intitiator is 
                                //the same as the drop target, then we are just 
sorting.
                                        for(var j = 0; j < 
event.target.dataProvider.length; j++){
                                                
if(event.target.dataProvider[j].NUMPROJECTID ==
items[i].NUMPROJECTID && event.dragSource._data.source.__id !=
event.target.id){
                                                        //if the dragged item 
exists in the drop list AND the item is
being dragged from the project list, then item exists
                                                        itemExists = "1"
                                                }
                                        }
                                        if(itemExists == "0"){
                                                dest.addItemAt(dropLoc, 
items[i]);
                                        }else{
                                                itemExists = "0"; //reset
                                        }
                        }
                        
                        //any time an item is added to a list or the sort order 
has
changed, update the record in the DB
                        //doUpdateTarget(event);
                        
                        //reset the projects array to the current project list
                        aProjects = new Array();//clear out the array each time
                        for(var i = 0; i < event.target.dataProvider.length; 
i++){
                                
aProjects.push(event.target.dataProvider[i].NUMPROJECTID)
                        }
                        
                        //resest the personnelID to the current list's owner
                        numPersonnelID = 
event.target._parent.dataProvider.NUMPERSONNELID
                        //and then update that list owner's record
                        
EventBroadcaster.getInstance().broadcastEvent("assignmentsUpdate");
                }
                
                //-------------------------------------
                private function doDragDelete(event) {
                
                        doDragExit(event);
                        var items = event.dragSource.dataForFormat("items");
                        var dest = event.target;
                        var dropLoc = dest.getDropLocation();
                        var sourceProvider = 
event.dragSource._data.source.dataProvider;
                        
                        //mx.core.Application.alert(event.target.id);
                        //mx.core.Application.alert('TRASH');
                        
                
//mx.core.Application.alert(event.target.dataProvider[0].TXTPROJECTNAME
+' '+ items.length );
                        
                        //any time an item is added to a list or the sort order 
has
changed, update the record in the DB
                        //doUpdateInitiator(event);
                        
                        //reset the projects array to the current project list 
MINUS THE
ITEM BEING DELETED
                        aProjects = new Array();//clear out the array each time
                        
                        //mx.core.Application.alert("source:
"+sourceProvider[i].NUMPROJECTID +"item: "+items[i].NUMPROJECTID);
                        for(var i = 0; i <sourceProvider.length; i++){
                                for(var n = 0; n < items.length; n++){
                                        if(sourceProvider[i].NUMPROJECTID != 
items[n].NUMPROJECTID){
                                                
aProjects.push(sourceProvider[i].NUMPROJECTID)
                                        }
                                }
                        }
                        
                        //resest the personnelID to the current list's owner
                        numPersonnelID =
event.dragSource._data.source._parent.dataProvider.NUMPERSONNELID
                        //and then update that list owner's record
                        
EventBroadcaster.getInstance().broadcastEvent("assignmentsUpdate");
                }
                
                //-------------------------------------
                private function doDragComplete(event) {
                        doDragExit(event);
                        var src = event.target;
                                
                        if (event.action == DragManager.MOVE) {
                
                                var items = src.selectedIndices;
                
                           items.sort(sortByNumber)             // If user 
selects the listitems in
random order, we first sort the array to have all the items in order
                           items.reverse()                      // then we 
reverse the array. In list
when any item is removed, it decreases the index of the items below it.
                                                                                
        // so we remove the bottom most item first.
                                var s="";
                                for(var i = 0; i < items.length; i++) {
                                        s=s+items[i]+" : ";
                                }
                
                                for(var i = 0; i < items.length; i++) {
                                        src.removeItemAt(items[i])
                                }
                
                        }
                }
                
                //-------------------------------------
                private function sortByNumber(a, b) {
                  return (a > b);
                }
                
        
//-----------------------------------------------------------------------------------
                private function getAllAssignments(){
                        
EventBroadcaster.getInstance().broadcastEvent("assignmentsGet",{
targetViewHelperName: 'projectAssignmentsViewHelper'});}
                
        
//-----------------------------------------------------------------------------------
                private function doUpdateTarget(event){
                
                        //reset the projects array to the current project list
                        aProjects = new Array();//clear out the array each time
                        for(var i = 0; i < event.target.dataProvider.length; 
i++){
                                
aProjects.push(event.target.dataProvider[i].NUMPROJECTID)
                        }
                        
                        //resest the personnelID to the current list's owner
                        numPersonnelID = 
event.target._parent.dataProvider.NUMPERSONNELID
                        //and then update that list owner's record
                        
EventBroadcaster.getInstance().broadcastEvent("assignmentsUpdate");
                }
                
        
//-----------------------------------------------------------------------------------
                private function doUpdateInitiator(event){
                
                        //reset the projects array to the current project list
                        aProjects = new Array();//clear out the array each time
                        for(var i = 0; i <
event.dragSource._data.source.dataProvider.length; i++){
                        
aProjects.push(event.dragSource._data.source.dataProvider[i].NUMPROJECTID)
                        }
                        
                        //resest the personnelID to the current list's owner
                        numPersonnelID =
event.dragSource._data.source._parent.dataProvider.NUMPERSONNELID
                        //and then update that list owner's record
                        
EventBroadcaster.getInstance().broadcastEvent("assignmentsUpdate");
                }
                
                private function temp(){
                        //used for testing
                        mx.core.Application.alert('itemrolled over');
                }

                
        
//-----------------------------------------------------------------------------------
        ]]>
        </mx:Script>

        <!--
============================================================================================
-->
                
        <mx:Tile id="personnelTile" direction="horizontal" width="100%"
height="100%">
        <mx:Repeater id="personnelRepeater" startingIndex="0">
                        <mx:Panel id="personnelPanel">
                                <mx:List id="personnelList" width="150" 
dragEnabled="true"
labelField="TXTPROJECTNAME" 
                                        itemRollOver="temp()"   
                                        dragEnter="doDragEnter(event)"
                                        dragExit="doDragExit(event);"
                                        dragOver="doDragOver(event);"
                                        dragDrop="doDragDrop(event);" 
                                        dragComplete="doDragComplete(event);"
                                />

                                                                
                                <mx:Box id="trash" width="100%" 
horizontalAlign="right"
                                        dragEnter="doDragEnter(event)"
                                        dragExit="doDragExit(event);"
                                        dragOver="doDragOver(event);"
                                        dragDrop="doDragDelete(event);" >
                                        <mx:Image source="media\TRASHCAN.jpg" />
                                </mx:Box>
                        </mx:Panel>
        </mx:Repeater>
        </mx:Tile>
        
</mx:VBox>
                





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/u8TY5A/tzNLAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to