1

I am building a flex project involving drag+drop of fxg graphics

my graphic is instantiated as below

  <graphics:arrow2 id="object" mouseMove="mouseMoveHandler(event);" />

I get an error: "Call to a possibly undefined method Graphic."

This works if I change my drag-object to Image and replace the 'Graphic' below with 'Image'. What should I use to be able to reference the fxg graphic in the drag-drop?

my drag drop functionality is as follows

private function mouseMoveHandler(event:MouseEvent):void
        {
                            var dragInitiator:Graphic = Graphic(event.currentTarget);
            var ds:DragSource = new DragSource();
            ds.addData(dragInitiator,"gph");
            DragManager.doDrag(dragInitiator, ds, event);

        }
        private function dragEnterHandler(event:DragEvent):void {

            if (event.dragSource.hasFormat("gph"))
            {
           DragManager.acceptDragDrop(SkinnableContainer(event.currentTarget));
            }

        }

        private var objectX:Number;


        private function dragDropHandler(event:DragEvent):void {

            objectX= SkinnableContainer(event.currentTarget).mouseX+50;


            Graphic(event.dragInitiator).x = objectX;
            Graphic(event.dragInitiator).y = 100;

        }
J_A_X
  • 12,857
  • 1
  • 25
  • 31
RG1967
  • 378
  • 1
  • 15

1 Answers1

0

This is an example taken from SaturnBoy:

<s:Application
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark">

    <fx:Script>
        <![CDATA[
            imports...

            private function mouseDownHandler(e:MouseEvent):void {
                DragManager.doDrag(e.currentTarget as IUIComponent, null, e);
            }

            private function dragEnterHandler(e:DragEvent):void {
                DragManager.acceptDragDrop(e.currentTarget as IUIComponent);
            }

            private function dragDropHandler(e:DragEvent):void {
                e.currentTarget.addElement(e.dragInitiator);
            }
        ]]>
    </fx:Script>

    <s:Panel title="src" width="100" minHeight="133" x="10" y="10">
        <s:Graphic width="80" height="80"
                mouseDown="mouseDownHandler(event)">
            <s:Rect ... </s:Rect>
        </s:Graphic>

        <s:Graphic width="80" height="80"
                mouseDown="mouseDownHandler(event)">
            <s:Ellipse ... </s:Ellipse>
        </s:Graphic>
        ...
    </s:Panel>

    <s:Panel title="target" width="100" minHeight="133" x="120" y="10"
            dragEnter="dragEnterHandler(event);"
            dragDrop="dragDropHandler(event);">
        ...
    </s:Panel>
</s:Application>
J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • i tried this prior to posting- guess don't know how to apply this to my needs. Not sure how the positioning control works – RG1967 Apr 27 '11 at 18:03
  • What do you mean positioning control? Does this example not function? – J_A_X Apr 27 '11 at 18:07
  • I get an exception : Cannot access a property or method of a null object reference. at DragManager.doDrag(event.currentTarget as IUIComponent, null, event);. Also unclear how I do some finer adjustments which I try to do in my version of dragdrophandler- e.g. I will not let the y coordinate change; slightly shift the x coordinate from mouse-drop – RG1967 Apr 27 '11 at 18:13
  • yes- double-checked- could it be because I am using a fxg created in Illustrator and introduced as component vs one created in mxml like here? – RG1967 Apr 27 '11 at 19:16
  • The end result should be the same unless the root node is different. It needs to be contained in a UIComponent. What's the root node of your illustrator made fxg file? – J_A_X Apr 27 '11 at 19:22
  • root node is Graphic- no UI component referenced here!! – RG1967 Apr 28 '11 at 03:33
  • Actually, [Graphic](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/primitives/Graphic.html) extends UIComponent, so you should be good. I suggest you edit your original post to include more code, or maybe just a small code 'test' to try to represent what you're doing. – J_A_X Apr 28 '11 at 11:48
  • ok- will do...guess need to send the Illustrator graphic/ code ... will raise separate answer and provide that – RG1967 Apr 29 '11 at 09:05