Hallo,
also bei meiner lokal installierten "Tour de Flex" gibt es da Beispiele dazu. Leider finde ich die nicht in der online Version der "Tour de Flex". Bei meiner lokalen Version steht da etwas von 713 Samples, bei der online Version nur 664. Die online Version ist V1.2.1, meine lokale V2.0. Keine Ahnung was die da machen, aber scheinbar wird die online Version nicht gepflegt.
Hier:
Tour de Flex | Adobe Flex Developer Center
Kannst du dir das installieren.
Bei mir gibt es da extra nen Menüpunkt "Air Applications/Air APIs and Techniques" und dort "Drag and Drop (2)".
Fallst Du es nicht findest hier noch den Code:
PHP-Code:
// DragIn.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
backgroundColor="#323232" styleName="plain" width="100%" height="100%">
<fx:Script>
import mx.managers.DragManager;
import mx.core.IUIComponent;
</fx:Script>
<mx:nativeDragEnter>
// Event handler for when something is dragged over to the WindowedApplication
// Only allow files to be dragged in
if (event.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT))
{
var files:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
// only allow a single file to be dragged in
if (files.length == 1)
{
DragManager.acceptDragDrop(event.currentTarget as IUIComponent);
setStyle("backgroundColor", 0xccccff);
}
}
</mx:nativeDragEnter>
<mx:nativeDragExit>
// Event handler for when the drag leaves the WindowedApplication
setStyle("backgroundColor", 0x323232);
</mx:nativeDragExit>
<mx:nativeDragDrop>
// Event handler for when a dragged item is dropped on the WindowedApplication
var arr:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
startImage.source = (arr[0] as File).url;
</mx:nativeDragDrop>
<mx:ViewStack id="startVS" width="100%" height="100%" creationPolicy="all">
<mx:Canvas width="100%" height="100%">
<mx:Text verticalCenter="0" horizontalCenter="0" color="white">
<mx:htmlText><![CDATA[<font size="20"><b>Drag an image here</b></font>]]></mx:htmlText>
</mx:Text>
</mx:Canvas>
<mx:Canvas width="100%" height="100%">
<mx:Image id="startImage" width="100%" height="100%" horizontalAlign="center" verticalAlign="middle" complete="startVS.selectedIndex = 1;"/>
</mx:Canvas>
</mx:ViewStack>
</s:WindowedApplication>
PHP-Code:
// DragOut.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
backgroundColor="#323232" styleName="plain" width="100%" height="100%">
<fx:Script>
[Bindable]private var logo:File = new File("app:/air-logo.jpg");
[Embed("air-logo-icon.jpg")]
private var logoIconClass:Class;
</fx:Script>
<s:VGroup horizontalAlign="center">
<s:Label text="Drag the image out of the application" color="white"/>
<mx:Image id="image" source="{logo.url}" width="90%" height="90%" horizontalAlign="center" verticalAlign="middle">
<mx:mouseDown>
// Event handler which begins the drag
// Allow the image to be dragged as either a file or a bitmap
var transfer:Clipboard = new Clipboard();
transfer.setData(ClipboardFormats.BITMAP_FORMAT, Bitmap(image.content).bitmapData);
transfer.setData(ClipboardFormats.FILE_LIST_FORMAT, new Array(logo), false);
// only allow the file to be copied
var dragOptions:NativeDragOptions = new NativeDragOptions();
dragOptions.allowMove = false;
dragOptions.allowCopy = true;
dragOptions.allowLink = false;
// create an icon to display when dragging
var iconBitmapData:BitmapData = (new logoIconClass() as Bitmap).bitmapData;
// begin the drag
NativeDragManager.doDrag(this, transfer, iconBitmapData, null, dragOptions);
</mx:mouseDown>
</mx:Image>
</s:VGroup>
</s:WindowedApplication>
Have Fun