Hi, This is old flash way to do drag and drop, it's for users love doing stuff low-level way. BTW! OO purist might not like it ;). It's not for production level of code, my intention is to show one of the possible way.
##DragDropExample.mxml## <?xml version="1.0" encoding="iso-8859-1"?> <mx:Application width="800" height="600" xmlns:mx="http://www.macromedia.com/2003/mxml" creationComplete="appInit()"> <mx:Style> Label { font-size:15; color:#FFFFFF; } </mx:Style> <mx:Script> <![CDATA[ var bMouseDown:Boolean = false; var objectBeingDragged:Object; var origLocs:Object = {}; var targets:Object = {}; var dragDepth:Number; function appInit() { origLocs[source1] = {x:source1.x, y:source1.y}; origLocs[source2] = {x:source2.x, y:source2.y} targets[source1] = target1; targets[source2] = target2; dragDepth = cvs.getNextHighestDepth(); } function handleMouseDown(event) { bMouseDown = true; objectBeingDragged = event.target; var tmp = objectBeingDragged.getDepth(); //set the depth of object to the highest in the Canvas. objectBeingDragged.swapDepths(dragDepth) //store the depth of the object dragDepth = tmp; } function handleMouseMoveSomewhere(event) { if(bMouseDown) { //start dragging the object, 'true' means that mouse pointer is locked to top-left corner of object. objectBeingDragged.startDrag(true); //force screen update updateAfterEvent(); } } function handleMouseUpSomewhere(event) { if(bMouseDown) { //stop dragging.. objectBeingDragged.stopDrag(); bMouseDown = false; //get the center co-ords of object.. var x = objectBeingDragged.x + objectBeingDragged.width/2; var y = objectBeingDragged.y + objectBeingDragged.height/2; //get the target for this objects from hashmap var target = targets[objectBeingDragged]; //target's bound var tx = target.x; var ty = target.y; var th = target.height; var tw = target.width; //detect if x, y of object dropped falls in the bounds of target if ((x >= tx && x<= (tx + tw)) && (y >= ty && y<= (ty + th))) { //create a label in target container, and set the text..this is just sample it might not be making sense :) target.createChild(mx.controls.Label,"", {text:"Object dropped on me is: " + objectBeingDragged.text}); } else { target.createChild(mx.controls.Label,"", {text:"Source 1 dropped on Wrong target..., Drop here.."}); } //restore the position of draggable once work is done, you can hide it or remove it, depends on your requirement... objectBeingDragged.x = origLocs[objectBeingDragged].x; objectBeingDragged.y = origLocs[objectBeingDragged].y; //restore the depth of draggable.. var tmpDepth = objectBeingDragged.getDepth(); objectBeingDragged.swapDepths(dragDepth); dragDepth = tmpDepth; objectBeingDragged = null; } } ]]> </mx:Script> <mx:Canvas id="cvs" width="600" height="500"> <mx:Label id="source1" text="Source 1" mouseDown="handleMouseDown(event)" mouseMoveSomewhere="handleMouseMoveSomewhere(event)" mouseUpSomewhere="handleMouseUpSomewhere(event)" x="10" y="10" /> <mx:Label id="source2" text="Source 2" mouseDown="handleMouseDown(event)" mouseMoveSomewhere="handleMouseMoveSomewhere(event)" mouseUpSomewhere="handleMouseUpSomewhere(event)" x="10" y="220" /> <mx:VBox id="target1" x="200" y="10" width="400" height="200" backgroundColor="#CCCCCC"/> <mx:VBox id="target2" x="200" y="220" width="400" height="200" backgroundColor="#CCCCCC"/> </mx:Canvas> </mx:Application> -abdul -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] Sent: Friday, April 22, 2005 3:01 AM To: [email protected] Subject: [flexcoders] Re: DATE Function in Flex Thanks. That worked great! Alex --- In [email protected], Abdul Qabiz <[EMAIL PROTECTED]> wrote: > Hi Alex > > Date Object in Flex(ActionScript) is quite powerful and allows you do things > more easily... > > var _date = new Date(2004, 11, 31); //11 means december, months are 0 > based... > > _date.setDate(_date.getDate() + 1); //sets _date to 01/0/2005, again 0 means > jan > > > Or you can extend the Date class and add the desired functions... > > class DateEx extends Date > { > ... > ... > > function addDays(count) > { > setDate(getDate() + count); > } > ... > ... > } > > var _date = new DateEx(2004, 11, 31); > _date.addDays(1); > > > -abdul > > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] > Sent: Friday, April 22, 2005 12:33 AM > To: [email protected] > Subject: [flexcoders] DATE Function in Flex > > > > .NET has a nice set of date functions that will allow you to add or > subtract days from a selected date. > > For Example: > > my date is 12/31/2004 > myDate.AddDays(1) would set the myDate equal to 01/01/2005 > > From reading the documentation, I don't see such capabilities in the > Flex Date class. Is there any such functionality WITHOUT re- inventing > the wheel and writing your own function from scratch? > > Thanks, > Alex > > > > > > > Yahoo! Groups Links Yahoo! Groups Links 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/

