我正在构建一个涉及拖放fxg图形的flex项目
我的图形实例化如下
<graphics:arrow2 id="object" mouseMove="mouseMoveHandler(event);" />
我收到错误:“调用可能未定义的方法Graphic。”
如果我将drag-object更改为Image并将下面的'Graphic'替换为'Image',则此方法有效。我应该使用什么来引用拖放中的fxg图形?
我的拖放功能如下
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;
}
答案 0 :(得分:0)
这是取自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>