3 Replies Latest reply on Aug 1, 2008 4:25 PM by VarioPegged

    weird behavior/bug with canvas drag and drop

    repairman123
      Hi guys,
      I spent several days and finally figured out some weird issue with drag and drop to a canvas. It seems like if the "backgroundColor" attribute of canvas is not set then you cannot drag and drop to it. This is ridiculous to the extreme! what does drag and drop have to do with backgroundcolor of the target? Does flex have some bug tracking system where i can file a bug? See the code below where if you set the backgroundColor attribute then you can see it lets canvas to be the target when you drag the image over the canvas. But if you delete backgroundColor then it shows the red cross when you drag the image over canvas. Is there any logical explaination? By the way, is there a forum where flex issues are posted and developers from adobe actually read?
      ======================================
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" width="374" height="406">

      <mx:Script>
      <![CDATA[
      import mx.events.*;
      import mx.core.*;
      import mx.managers.DragManager


      private function doDrag(event:MouseEvent):void
      {
      var img:Image = event.currentTarget as Image;
      var dragImg:Image = new Image();
      dragImg.source = img.source;

      var dsource:DragSource = new DragSource();
      dsource.addData(img, 'img');

      DragManager.doDrag(img, dsource, event, dragImg);
      }

      private function dragAccept(event:DragEvent):void
      {
      DragManager.acceptDragDrop(Canvas(event.currentTarget))
      }

      ]]>
      </mx:Script>


      <mx:Image name="Bioshock" source=" http://www.adobe.com/devnet/images/214x74/max08_214.jpg" mouseDown="doDrag(event)" />

      <mx:Canvas x="0" y="255" width="174" height="151"
      borderStyle="solid" backgroundColor="#FFFFFF"
      dragEnter="dragAccept(event)">
      </mx:Canvas>

      </mx:Application>
        • 1. Re: weird behavior/bug with canvas drag and drop
          Level 7

          "repairman123" <webforumsuser@macromedia.com> wrote in message
          news:g6u7s1$ot9$1@forums.macromedia.com...
          > Hi guys,
          > I spent several days and finally figured out some weird issue with drag
          > and
          > drop to a canvas. It seems like if the "backgroundColor" attribute of
          > canvas
          > is not set then you cannot drag and drop to it. This is ridiculous to the
          > extreme! what does drag and drop have to do with backgroundcolor of the
          > target? Does flex have some bug tracking system where i can file a bug?
          > See the code below where if you set the backgroundColor attribute then you
          > can
          > see it lets canvas to be the target when you drag the image over the
          > canvas.
          > But if you delete backgroundColor then it shows the red cross when you
          > drag the
          > image over canvas. Is there any logical explaination? By the way, is
          > there a
          > forum where flex issues are posted and developers from adobe actually
          > read?

          Try giving it a backgroundColor but also make the backgroundAlpha 0.


          • 2. Re: weird behavior/bug with canvas drag and drop
            repairman123 Level 1
            well, that's point. I know adding backgroundColor value will allow the drag and drop. The question is Why? what does background color have to do with drag being accepted? It's like your saying the car will only shift gear if I am wear tennis shoes! Completely illogical! Must be bug. But where I file the bug? is adobe bug database?
            • 3. Re: weird behavior/bug with canvas drag and drop
              VarioPegged
              This is not a bug! This is how containers behave. With Canvas, HBox, etc., without backgroundColor set, there is no physical (graphic) object that the dragged object can intersect with.

              From the Flex documentation:

              To use a container as a drop target, you must use the backgroundColor property of the container to set a color. Otherwise, the background color of the container is transparent, and the Drag and Drop Manager is unable to detect that the mouse pointer is on a possible drop target.

              TS