PDA

View Full Version : [AIR] Draging Files



Gazurt
October 8th, 2007, 02:11 PM
I have a code:
import flash.desktop.TransferableData
import flash.events.NativeDragEvent;

function suruklendiginde(event:NativeDragEvent):void {

var trData:TransferableData = event.transferable;
if (trData.hasFormat(TransferableFormats.FILE_LIST_FO RMAT)) {

var d:Array = trData.dataForFormat(TransferableFormats.FILE_LIST _FORMAT, TransferableTransferMode.ORIGINAL_PREFERRED) as Array;

for (var i:int=0; i<d.length; i++) {
if (d[i].extension == "mp3") {
DragManager.acceptDragDrop(this);
}
}
}
}

function birakildiginda(event:NativeDragEvent):void {
var trData:TransferableData = event.transferable;
if (trData.hasFormat(TransferableFormats.FILE_LIST_FO RMAT)) {
var d:Array = trData.dataForFormat(TransferableFormats.FILE_LIST _FORMAT, TransferableTransferMode.ORIGINAL_PREFERRED) as Array;
trace(d);
}
}
this.addEventListener(NativeDragEvent.NATIVE_DRAG_ ENTER, suruklendiginde);
this.addEventListener(NativeDragEvent.NATIVE_DRAG_ DROP, birakildiginda);

It doesn't work.I think the problem is version... My AIR version is Beta 2... But the codes from Beta 1.In Adobe Labs:
http://livedocs.adobe.com/labs/flex/3/langref/

The codes look same... So where is the problem?

Thanks...

senocular
October 8th, 2007, 02:13 PM
do you have that code in the target movie clip you want to drag the MP3 files on?

Gazurt
October 8th, 2007, 02:31 PM
I think the main problem is here:
ActionScript Code:

import flash.desktop.DragManager;
import flash.desktop.TransferableFormats;
import flash.events.NativeDragEvent;
import flash.filesystem.File;





I only wrote that codes but it gives error.It's number is 1172

EDIT:Codes are in the root

senocular
October 8th, 2007, 02:52 PM
numbers mean nothing, post the error message :sure:

Stratification
October 8th, 2007, 02:55 PM
Yeah, there were some changes in the location of those classes if I remember right. What are the exact errors you're getting?

Gazurt
October 8th, 2007, 02:58 PM
Then the error message :P

Definition flash.desktop:TransferableFormats could not be found
Definition flash.desktop:TransferableFormats could not be found

Yes there is two same error :D

Gazurt
October 9th, 2007, 09:44 AM
I can't solve the problem... Why gives that errors?

senocular
October 9th, 2007, 11:22 AM
You're using Flash right? Did you install the AIR update for Flash?
http://labs.adobe.com/wiki/index.php/AIR:Flash_CS3_Professional_Update

wimvanhenden
October 9th, 2007, 11:48 AM
Hey guys,

Drag and drop has been changed in beta2. TransferableData and TransferableFormats are gone. They have been replaced with Clipboard and ClipboardFormats.
I've posted the solution here, check it out:
http://seeing-is-believing.blogspot.com/2007/10/adobe-air-beta-2-drag-and-drop-window.html

senocular
October 9th, 2007, 11:53 AM
Ok, I see now. They didn't update the docs yet ( http://www.adobe.com/go/learn_flex3_aslr ) but the release notes ( http://labs.adobe.com/wiki/index.php/AIR:Release_Notes ) indicate it. Thanks wimvanhenden :)

Gazurt
October 9th, 2007, 12:12 PM
I understood that they were updated but now How will be my code? Because when I just wrote:

import desktop.Clipoard;
import desktop.ClipboardFormats;

It gives the same error :(

senocular
October 9th, 2007, 12:17 PM
flash.desktop...

Gazurt
October 9th, 2007, 12:18 PM
flash.desktop...

hahaha :D:cantlook::P sorry guys :)

Gazurt
October 9th, 2007, 12:33 PM
This is the new version:

import flash.desktop.*;
import flash.events.*;

function onDrop(e:NativeDragEvent):void {

DragManager.dropAction = DragActions.COPY;

var d:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FOR MAT) as Array;
trace(d);

}
function onDrag(e:NativeDragEvent):void {
var d:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FOR MAT) as Array;
for (var i:int=0; i<d.length; i++) {
if (d[i].extension == "mp3") {
DragManager.acceptDragDrop(ekran);
}
}
}
ekran.addEventListener(NativeDragEvent.NATIVE_DRAG _DROP, onDrop);
ekran.addEventListener(NativeDragEvent.NATIVE_DRAG _ENTER, onDrag);

create a square.Its instance name must be ekran... Then test it ;)