0 Replies Latest reply on May 14, 2015 5:59 AM by N4nd0

    Error drag and drop

    N4nd0

      Good morning, I'm trying to make drag and drop in eclipse to connect to the bank by blazeds an image inside a canvas that would be a board and is presenting the following error:


      RangeError:Error#2006:The supplied index is out of bounds.

      at flash.display:DisplayObjectContainer/addChildAt()

      at mx.core:Container/addChildAt()[E:\dev\3.0x\frameworks\projects\framework\src\mx\core\Cont ainer.as:2206]

      at mx.core:Container/addChild()[E:\dev\3.0x\frameworks\projects\framework\src\mx\core\Contai ner.as:2140]

      at tabuleiro/handleDragDrop()[D:\Programação\Eclipse\workspace\tabuleiro\flex_src\scripts\dr agDrop.as:156]

      at tabuleiro/__tabuleiro_DragDrop()[D:\Programação\Eclipse\workspace\tabuleiro\flex_src\tabu leiro.mxml:6]

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at mx.cre::UiComponent/dispatchEvent()[E:\dev\3.0x\frameworks\projects\framework\src\mx\core \UIComponent.as:9051]

      at mx.managers.dragClasses::DragProxy/mouseUpHandler()[E:\dev\3.0x\frameworks\projects\frame work\src\mx\managers\dragClasses\DragProxy.as:500]

       

      Note: in FlexBuilder 3 works perfectly.


      My calls in mxml file:


      [code]

      <mx:Canvas id="canvasTabuleiro" width="628" height="702" backgroundColor="#FFFFFF" borderStyle="solid"

      borderColor="#000000" dragDrop="{handleDragDrop(event)}" dragEnter="{handleDragEnter(event)}">

      <mx:Image id="tabuleiro"

        source="@Embed(source='assets/tabuleiro.jpg')" width="626" height="391"/>

      <mx:Image id="imagem1" x="10" y="399" source="@Embed(source='assets/peca.jpg')" mouseDown="handleMouseDown(event)"/>

      [/code]


      My dragDrop.as file:


      [code]

      import flash.events.MouseEvent;

      import mx.controls.Image;

      import mx.core.DragSource;

      import mx.core.IUIComponent;

      import mx.core.UIComponent;

      import mx.events.DragEvent;

      import mx.managers.DragManager;

             

       

       

              private function handleMouseDown( event:MouseEvent ):void

              {

                 

                  if ( event.currentTarget is IUIComponent )

                  {

         

                      var dragChild:UIComponent = UIComponent( event.currentTarget );

       

                      var dragSource:DragSource = new DragSource();

                      dragSource.addData( dragChild.parent, 'dragParent' );

                      dragSource.addData( dragChild, 'dragChild' );

                     

       

                      var proxy:UIComponent = UIComponent( event.currentTarget );

       

                      var bitmapData:BitmapData = new BitmapData( proxy.width, proxy.height );

                      bitmapData.draw( proxy );

                     

                     

                      var bitmap:Bitmap = new Bitmap( bitmapData );

                 

                      var image:Image = new Image();

                      image.source = bitmap;

                     

                     

                      DragManager.doDrag( dragChild, dragSource, event, image );

                 

              private function handleDragEnter( event:DragEvent ):void

              {

                  if ( event.dragSource.hasFormat('dragChild') && event.dragSource.hasFormat('dragParent') )

                  {

                     

                      if ( event.currentTarget is UIComponent )

                      {

                         

                          var dropTarget:UIComponent = UIComponent( event.currentTarget );                   

       

                                         

                          var dragSource:UIComponent = event.dragSource.dataForFormat( 'dragParent' ) as UIComponent;

                         

                              DragManager.acceptDragDrop( dropTarget );       

                              DragManager.showFeedback( DragManager.COPY );  

       

                                             

                          

                      }

                     

                  }

                 

              }

             

       

             

              private function handleDragDrop( event:DragEvent ):void

              {           

                 

                  if ( event.currentTarget is UIComponent )

                  {

                     

                      var dropTarget:UIComponent = UIComponent( event.currentTarget );

         

                     

                      var dragSource:UIComponent = event.dragSource.dataForFormat( 'dragParent' ) as UIComponent;

                     

                          var child:UIComponent = event.dragSource.dataForFormat( 'dragChild' ) as UIComponent;

                         

                                                 

                         

                          Image(event.dragInitiator).x = Canvas(event.currentTarget).mouseX;

                          Image(event.dragInitiator).y = Canvas(event.currentTarget).mouseY;

                          //dragSource.removeChild( child );

                          dropTarget.addChild( child );

                         

       

                             

                             

                          }       

                     

       

                  }

                 

              }

      [/code]


      Well, as it worked in FlexBuilder not imagine what to do to correct the Eclipse. Thanks in advance.