Skip to main content
Aug 1, 2011 5:27 PM UTC
Question

Problem with drag and drop files from remove lan server

Hi all hope you are all good,

Im a little new to Adobe Air but have good amount of experience with AS3.

i've been struggling with this for quite some time now.

I got to create a drag and drop that i made to check on banners like fps, width, height etc.

It works perfectly with local files, but since we usually check peoples files on a remote lan server, Adobe Air doesnt seem to find the paths to the server, thus shows an IOError.

I have been looking for a solution to this using LoaderContext, changing the local with network, etc, no luck.

If anybody could give me some light would be greatly appreciated.

this is my code:

package

{

import flash.desktop.ClipboardFormats;

import flash.desktop.NativeApplication;

import flash.desktop.NativeDragManager;

import flash.display.Bitmap;

import flash.display.BitmapData;

import flash.display.Loader;

import flash.display.LoaderInfo;

import flash.display.MovieClip;

import flash.events.IOErrorEvent;

import flash.events.NativeDragEvent;

import flash.events.TimerEvent;

import flash.filesystem.File;

import flash.display.Sprite;

import flash.events.Event;

import flash.events.MouseEvent;

import flash.geom.Rectangle;

import flash.net.URLRequest;

import flash.system.ApplicationDomain;

import flash.system.Capabilities;

import flash.system.LoaderContext;

import flash.text.AntiAliasType;

import flash.text.TextField;

import flash.display.Stage;

import flash.text.TextFieldAutoSize;

import flash.text.TextFieldType;

import flash.utils.Timer;

/**

* ...

* @7111211 Francisco Chong

*/

public class Main extends Sprite

{

private var time:TextField;

private var stage_back:Sprite = new Sprite();

private var stage_item_holder:Sprite = new Sprite();

private var stage_loaded_items:Sprite = new Sprite();

private var n:TextField;

private var loader:Loader;

private var bannertimer:Timer;

private var bannerTimerSecs:int = 0;

public function Main():void

{

addChild(stage_back);

addChild(stage_item_holder);

stage_loaded_items.y = 200;

addChild(stage_loaded_items);

stage_back.addEventListener(MouseEvent.MOUSE_DOWN, drag);

// Align native AIR application window horizontally and vertically

stage.nativeWindow.x = (Capabilities.screenResolutionX - stage.nativeWindow.width) / 2;

stage.nativeWindow.y = (Capabilities.screenResolutionY - stage.nativeWindow.height) / 2;

addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragEnter);

addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop);

bannertimer = new Timer(1000);

bannertimer.addEventListener(TimerEvent.TIMER, handleTimer);

init();

}

private function handleTimer(e:TimerEvent):void

{

++bannerTimerSecs;

time.text = bannerTimerSecs.toString();

}

private function onDragEnter(e:NativeDragEvent):void

{

NativeDragManager.acceptDragDrop(this);

}

private function onDragDrop(e:NativeDragEvent):void

{

if (bannertimer.running) {

bannertimer.stop();

bannerTimerSecs = 0;

time.text = "0";

}

var dropfiles:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;

for each (var file:File in dropfiles) {

switch (file.extension.toLowerCase()){

case "png" :

loadImage(file.nativePath);

break;

case "jpg" :

loadImage(file.nativePath);

break;

case "jpeg" :

loadImage(file.nativePath);

break;

case "gif" :

loadImage(file.nativePath);

break;

case "swf":

loadSwf(file.nativePath);

break;

default:

n.text = file.nativePath+" Error: INVALID FILE FORMAT";

//trace("Unmapped Extension");

}

}

}

private function loadSwf(str:String):void

{

var source:String;

if ((Capabilities.os.search("Mac")) >= 0) {

source = "file://"+str

}else {

source = str

}

if (loader) {

loader.unloadAndStop();

}

loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleSwfComplete);

//var apDomain:ApplicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);

//var context:LoaderContext = new LoaderContext(false, apDomain);

loader.load(new URLRequest(source));

}

private function loadImage(str:String):void {

var source:String;

if ((Capabilities.os.search("Mac")) >= 0) {

source = "file://" + str;

}else {

source = str;

}

if (loader) {

loader.unloadAndStop();

}

loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleImageComplete);

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleError);

loader.load(new URLRequest(source));

}

private function handleError(e:IOErrorEvent):void

{

for (var i:String in e) {

n.appendText( i + " >> " + e );

}

}

private function handleImageComplete(e:Event):void

{

var ld:Loader = e.currentTarget.loader as Loader;

var info:LoaderInfo = LoaderInfo(ld.contentLoaderInfo);

var imgBmp:Bitmap = Bitmap(ld.contentLoaderInfo.content);

var summary:String = String(" >> width:" + info.width + " >> height:" + info.height + " >> SIZE:"+Math.round((info.bytesTotal/1024)*100)/100+"Kb");

n.text = "";

n.text = summary;

ld.scrollRect = new Rectangle(0, 0, info.width, info.height);

stage_loaded_items.addChild(ld);

}

private function handleSwfComplete(e:Event):void

{

trace("swf complete")

var ld:Loader = e.currentTarget.loader as Loader;

trace(ld);

var info:LoaderInfo = LoaderInfo(ld.contentLoaderInfo);

trace(info);

var summary:String = String("fps:" + info.frameRate + " >> width:" + info.width + " >> height:" + info.height + " >> AS:" + info.actionScriptVersion + " >> SWFversion " + info.swfVersion+" >> SIZE:"+Math.round((info.bytesTotal/1024)*100)/100+"Kb");

if (!bannertimer.running) {

bannerTimerSecs = 0;

bannertimer.start();

}

n.text = "";

n.text = summary;

ld.scrollRect = new Rectangle(0, 0, info.width, info.height);

stage_loaded_items.addChild(ld);

}

private function drag(e:Event):void

{

stage.nativeWindow.startMove();

}

private function init():void {

n = new TextField();

n.autoSize = TextFieldAutoSize.LEFT;

n.x = 20;

n.y = 20;

n.text = "THIS IS A TEST";

stage_item_holder.addChild(n);

time = new TextField();

time.autoSize = TextFieldAutoSize.LEFT;

time.x = 20;

time.y = 40;

time.text = "0";

stage_item_holder.addChild(time);

var close:TextField = new TextField();

close.selectable = false;

close.width = 20;

close.autoSize = TextFieldAutoSize.LEFT;

close.mouseEnabled = false;

close.antiAliasType = AntiAliasType.NORMAL;

close.text = "X";

var closeButton:Sprite = new Sprite();

closeButton.graphics.beginFill(0xff0000, .5);

closeButton.graphics.drawRoundRect(0, 0, 20, 20, 5, 5);

closeButton.graphics.endFill();

closeButton.addChild(close);

closeButton.x = stage.stageWidth - (closeButton.width)

addChild(closeButton);

closeButton.buttonMode = true;

closeButton.mouseChildren = false;

closeButton.addEventListener(MouseEvent.CLICK, closeApp);

var s:Sprite = new Sprite();

s.graphics.beginFill(0xffcc00, 1);

s.graphics.drawRoundRect(0, 0, 900, 600,30,30);

s.graphics.endFill();

s.x = 0;

s.y = 0;

stage_back.addChild(s);

}

private function closeApp(e:MouseEvent):void

{

NativeApplication.nativeApplication.exit();

}

}

}

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Participant
Aug 11, 2011 12:47 PM UTC

Until the introduction of file promises in AIR Athena, it  has never been possible to drag remote files out of an AIR application.

You could refer to the http://www.adobe.com/devnet/air/flex/articles/using_file_promises.html

Hope this is helpful. Please let me know if I could help more.

Translate
chris.campbell
Legend
Aug 8, 2011 10:37 PM UTC

Sorry for the delay.  I've forwarded this along to our team, are you still running into problems with drag and drop?

Thanks,

Chris

Translate