5 Replies Latest reply on Apr 15, 2010 9:14 AM by David_F57

    event.dragSource.hasFormat for controls

    ravitejab4u

      I'm trying to implement drag and drop feature for the custom controls. i know that i've to use event.dragSource.hasFormat("img") for image. What is the format for datefield and other controls ?  Can anybody answer the following please.

       

      event.dragSource.hasFormat("radio")  for radio button

      event.dragSource.hasFormat("img")  for image

      event.dragSource.hasFormat("checkbox")  for check box

      event.dragSource.hasFormat("button")  for Button

      event.dragSource.hasFormat("txt")  for textinput

       

      What should be the values for following

       

      event.dragSource.hasFormat( ? )  for radiobuttongroup

      event.dragSource.hasFormat( ? )  for textarea

      event.dragSource.hasFormat( ? )  for richtexteditor

      event.dragSource.hasFormat( ? ) for list

      event.dragSource.hasFormat( ? )  for numericstepper

      event.dragSource.hasFormat( ? )  for datefield

      event.dragSource.hasFormat( ? )  for video display

      event.dragSource.hasFormat( ? )  for combobox

      event.dragSource.hasFormat( ? )  for colorpicker

       

      Thanks in advance.

       

      -ravi

        • 1. Re: event.dragSource.hasFormat for controls
          David_F57 Level 5

          Hi,

           

          You don't have to use "img" for an image, the hasformat is something you set so that when you drop an object you can determine what you want to happen, for instance if I have a page with a framed photo, I can drag either a photoframe or an image onto the object, so I set hasformat to "image" so the target knows the data is an image, I set the hasformat to "frame" for the border so the target knows the data consists of a photo frame.

           

          Also i might want to drag an icon over the target and when I 'drop' that icon I want a checkbox to be added so I  set hasformat=checkbox but there is no real data but what I do is use the drag properties to determine that for this operation I want to add a checkbox to the target.

           

          this isn't functional code -its to give you the logic of the above statement.

           

          if (hasformat="checkbox")

          {

          var chkbox: chkbox = new checkbox;

          target.addChild(chkbox);

          }

           

          David.

          • 2. Re: event.dragSource.hasFormat for controls
            ravitejab4u Level 1

            David,

             

            Thanks for the reply.

             

            I know what has to be done when an object is dropped. The logic you provided is exactly what i am trying to do. But i need to know what would be the format of the controls when they are dropped. I need to know which control has been dropped. Suppose if i drag datefiled what does hasformat ( ?) contains

             

            Any ideas.

             

            -ravi

            • 3. Re: event.dragSource.hasFormat for controls
              David_F57 Level 5

              Hi,

               

              You set the property so it can be what ever you want, so you use mousedown on the object to start the drag operation

               

                public function Dragit(event : MouseEvent) : void

                {

                        var target:Canvas = Canvas(event.currentTarget);

                        var sourceObject:Object = new Object(); <=== you can use this object tif you need to use properties such as textcontent of a text field

                        var sourceObject.text = event.currentTarget.text;

                        var sourceObject.width = event.currentTarget.width;

                        var sourceObject.width = event.currentTarget.height;

               

                        var dragSource:DragSource = new DragSource();

                        dragSource.addData( sourceObject, "Mytextfield");

                        mx.managers.DragManager.doDrag( target, dragSource, event, null , 0, 0, 0.40, true );

                }

               

               

              Assuming you have prepared a canvas to accept drag drop the following will add a textarea to it.

               

              private function doDragDrop(event:DragEvent): void

              {

               

              var MyObject : Object;        

              if (event.dragSource.hasFormat('Mytextfield'))

                      {

                       MyObject = new Object();

                       MyObject = event.dragSource.dataForFormat("Mytextfield");

                       var newtext:TextArea=new textArea();

                        newtext.text=MyObject.text;   

                        newtext.height=MyObject.height;   

                        newtext.text=MyObject.width;

                        newtext.y = event.localY-(newtext.height/2)  

                        newtext.x = event.localX-(newtext.width/2)  

                        event.currentTarget.addChild(newtext);

                       }

              David.

              • 4. Re: event.dragSource.hasFormat for controls
                ravitejab4u Level 1

                Thank you so much. That answers my question. Answer is always simple but we make it complicated. my stupid brain

                 

                I appreciate your help.

                 

                -ravi

                • 5. Re: event.dragSource.hasFormat for controls
                  David_F57 Level 5

                  Hi,

                   

                  Just note I type this of the top of my head and did a bit of cut n paste so the code below is wrong

                   

                            var sourceObject.text = event.currentTarget.text;

                            var sourceObject.width = event.currentTarget.width;

                            var sourceObject.width = event.currentTarget.height;

                   

                   

                  just remove the var bit....

                   

                   

                  David.