You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Trevor Holman <tr...@mchsi.com> on 2015/06/27 05:49:37 UTC
file extention
I have a function to handle saving a file for AIR. I'd like it to
automatically add the extension when saving, is there a way to add that to
the input when you browseForSave?
Trevor
Re: file extention
Posted by Trevor Holman <tr...@cqbookstore.com>.
Thanks, I’ll take a look at this… I’m not sure I understand it all at the moment.
> On Jun 27, 2015, at 9:18 AM, Robert N <su...@outlook.com> wrote:
>
> You can change it in the save event as the user could key anything in the save dialog and I do not know of any way to hook the key press event in that dialog.
>
> This is some 'old' code to change/force the ext, I originally got idea from someone's posting, and change it a bit:
>
>
> import flash.events.Event;
> import flash.filesystem.File;
> import flash.filesystem.FileMode;
> import flash.filesystem.FileStream;
>
> private var documentsDir:File;
> private const defaultExtensions:String = "ForcedExt";
> private const extensionList:Array = ["ForcedExt"];
>
> public function localSave():void {
> documentsDir = File.desktopDirectory;
> documentsDir.browseForSave("Save As");
> documentsDir.addEventListener(Event.SELECT, localSaveHandler);
> }
>
> function localSaveHandler(event:Event):void {
> documentsDir.removeEventListener(Event.SELECT, localSaveHandler);
> var pathArray:Array = File(event.target).nativePath.split(File.separator)
> var originalFileName:String = pathArray.pop();
> var newFileName:String = checkExt(originalFileName);
> pathArray.push(newFileName);
> var newURI:File = new File("file:///" + pathArray.join(File.separator));
> var stream:FileStream = new FileStream();
> stream.open(newURI, FileMode.WRITE);
> // Replace this with your actual file write routine.
> stream.writeUTFBytes("Your file contents");
> stream.close();
> }
>
> private function checkExt(fileURI:String):String {
> var fileExtension:String = fileURI.split(".")[1];
> for each(var it:String in extensionList) {
> if (fileExtension == it)
> return fileURI;
> }
> return fileURI.split(".")[0] + "." + defaultExtensions;
> }
>
>
> ----------------------------------------
>> From: trevorh@mchsi.com
>> To: users@flex.apache.org
>> Subject: file extention
>> Date: Fri, 26 Jun 2015 22:49:37 -0500
>>
>> I have a function to handle saving a file for AIR. I'd like it to
>> automatically add the extension when saving, is there a way to add that to
>> the input when you browseForSave?
>>
>>
>>
>> Trevor
>>
>
RE: file extention
Posted by Robert N <su...@outlook.com>.
You can change it in the save event as the user could key anything in the save dialog and I do not know of any way to hook the key press event in that dialog.
This is some 'old' code to change/force the ext, I originally got idea from someone's posting, and change it a bit:
import flash.events.Event;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
private var documentsDir:File;
private const defaultExtensions:String = "ForcedExt";
private const extensionList:Array = ["ForcedExt"];
public function localSave():void {
documentsDir = File.desktopDirectory;
documentsDir.browseForSave("Save As");
documentsDir.addEventListener(Event.SELECT, localSaveHandler);
}
function localSaveHandler(event:Event):void {
documentsDir.removeEventListener(Event.SELECT, localSaveHandler);
var pathArray:Array = File(event.target).nativePath.split(File.separator)
var originalFileName:String = pathArray.pop();
var newFileName:String = checkExt(originalFileName);
pathArray.push(newFileName);
var newURI:File = new File("file:///" + pathArray.join(File.separator));
var stream:FileStream = new FileStream();
stream.open(newURI, FileMode.WRITE);
// Replace this with your actual file write routine.
stream.writeUTFBytes("Your file contents");
stream.close();
}
private function checkExt(fileURI:String):String {
var fileExtension:String = fileURI.split(".")[1];
for each(var it:String in extensionList) {
if (fileExtension == it)
return fileURI;
}
return fileURI.split(".")[0] + "." + defaultExtensions;
}
----------------------------------------
> From: trevorh@mchsi.com
> To: users@flex.apache.org
> Subject: file extention
> Date: Fri, 26 Jun 2015 22:49:37 -0500
>
> I have a function to handle saving a file for AIR. I'd like it to
> automatically add the extension when saving, is there a way to add that to
> the input when you browseForSave?
>
>
>
> Trevor
>