Archive | Adobe AIR RSS feed for this section

Why has AIR file.browseForSave no FileFilter option

3 Jun

I try to create my own extension with a saved AIR file. The point in doing this is that the user knows what files are created by what program and a file without an extension is just plain ugly.

When you save a file in other programs you can choose to overwrite a file (that is created before or has a known extension) or create a new file. I tried to find a way in AIR to do this same thing. I found one article on an Adobe blog that uses a FileFilter in combination with a file.browseForSave but he is using it in a way that it has no effect and is pretty useless. He is creating a FileFilter but he is never using it:

save:function(){
var fileFilter = new air.FileFilter("To Do Lists", "*.todo");
ToDo.currentDirectory.addEventListener(air.Event.SELECT, ToDo.fileSaved.bind(ToDo) );
ToDo.currentDirectory.browseForSave("Save To-do List");
}

I hear you think “who cares about the FileFilter” because it sounds like a minor problem and maybe it is. But for me it seems easy to build because browse(), browseForOpen() and browseForOpenMultiple() are using it.

I wonder if there is a way to work around this problem. It is maybe a little detail but it are the little details that make things great.

Air file.nativePath Vs. file.url

8 May

Is it me or is file.url a lot easier to use than file.nativePath in Adobe AIR. Maybe I’m missing something because every tutorial or code snippet I can find uses file.nativePath.

I’m busy building an AIR application that can be used on Windows and Mac OS. I have to take care of the file structure of both systems. After I test my application on a Mac I couldn’t load anything from it. The reason of this problem is that Mac needs “file://” in front of the file URL to load the file correct.

When I had this problem I searched the internet for a solution. I found very complex solutions at EverythingFlex and Snipplr. But then I start to examine the File object and found just the right file url (on the Mac it adds “file://” in front of the url) just accessible with File.url. Then I tested it on Windows and it worked perfect.

I see no reason why I shouldn’t use this simple version of all the long code solutions that are available on the web. But like I said maybe I’m missing something?

Direction of the TileList behaves strange

18 Apr

I stumbled into an incorrect working function of the TileList in Flex. It looks like they swopped a few variables around.

If you set the direction of the TileList to horizontal it looks like Flex doesn’t care about the option and just scolls vertical. After that I checked an Adobe quickstart guide to know sure that I wasn’t doing anything wrong. But I couldn’t find anything that I missed.

Because I hate it if things don’t work I try everything to get it working. So I tried to set the direction to vertical just to see if something was happening and now the TileList scolled horizontal… very strange.

here is a example with source code (right click)

TileList problem example

Maybe I’m doing something wrong? Do other people have the same problem?

Get full file path in AIR

1 Apr

Normally if you want a file path in Flex to upload a file you use FileReference() with a browse(). Last week I tried the same technique to get a file dragged from the desktop to my AIR application. After fixing a strange problem the code worked but the next problem appeared to me. With FileReference I only get the file name and I want the full path so save this to a SQLite database.

I searched quite some time to find the solution for this problem so I hope I save someone else his time with this explanation. In an AIR application you have an extra class called File. If you use this you get the full file path. Here is a little example code:

?View Code ACTIONSCRIPT
import mx.events.FileEvent;
private var openFile:File = new File()
 
private function openBrowseWindow():void{
	openFile.addEventListener(Event.SELECT, onOpenFileComplete);
	openFile.browse();
}
 
private function onOpenFileComplete(event:Event):void{
	trace("event: "+event.target.nativePath);
}

FileReferenceList() problem in AS3

21 Mar

Today I noticed a strange thing in Flex. Let me explain the problem.

I created FileReferenceList. I added a eventListener to that FileReferenceList that returns me the list of files that the user selects. This is the code:

?View Code ACTIONSCRIPT
private function openFileReference():void{
	var flr:FileReferenceList = new FileReferenceList();
	flr.addEventListener(Event.SELECT, onFrlResult);
	flr.browse();} 
 
private function onFrlResult(event:Event):void{
	trace("Select event: "+event.target);
}

When I tested the code I noticed that the function wasn’t called.

After that I tried to change the “FileReferenceList” to a “FileReference” and for the rest I kept the function the same. In this case my function “onFrlResult” was called. After some try and error I found the solution.

You can create a FileReference in a function but this is different with a FileReferenceList. You have to declare a variable with the type FileReferenceList outside the function. The final code will look like this:

?View Code ACTIONSCRIPT
private var flr:FileReferenceList;
?View Code ACTIONSCRIPT
private function openFileReference():void{
	this.flr = new FileReferenceList();
	this.flr.addEventListener(Event.SELECT, onFrlResult);
	this.flr.browse();
?View Code ACTIONSCRIPT
} 
 
private function onFrlResult(event:Event):void{
	trace("Select event: "+event.target);
}

I’m not sure if it is a problem/bug. Maybe there is a reason that you can’t create a variable with the type FileReferenceList inside a function. If someone knows why than please share it with me and leave a comment

Page 1 of 11