Browsing: Tutorials

Adobe AIR tips serie: browseForSave set default file extension and validate/modify.

November 17th, 2008 | By Cedric

postImage 01short Adobe AIR tips serie: browseForSave set default file extension and validate/modify. image
spacer Adobe AIR tips serie: browseForSave set default file extension and validate/modify. image

In this serie I propose some quick tips for Adobe AIR products developers, which came out during my regular practice of this technology. Today topic is:

Conforming extension for a browseForSave.

This short tip allows you to ensure that the file which will be saved following a browseForSave match legal extension you have defined beforehand and if not it will apply a default extension when using the browse for save functionality. Currently File.extension is a read only property and you cannot change it directly, so I decided to manipulate the path in order to allow it. I think a setExtension and allowedExtensions property might be useful in such a situation.

import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.events.Event;

private var docsDir:File;
private const MY_DEFAULT_EXTENSION:String = "abc";
private const VALID_EXTENSIONS_LIST:Array = ["abc"];

public function mySave():void
{
	docsDir = File.desktopDirectory;
	docsDir.browseForSave("Save As");
	docsDir.addEventListener(Event.SELECT, mySaveHandler);
}
private function mySaveHandler(event:Event):void
{
	docsDir.removeEventListener(Event.SELECT, mySaveHandler);
	//Split the returned File native path to retrieve file name
	var tmpArr:Array = File(event.target).nativePath.split(File.separator);
	var fileName:String = tmpArr.pop();//remove last array item and return its content
	//Check if the extension given by user is valid, if not the default on is put.
	//(for example if user put himself/herself an invalid file extension it is removed in favour of the default one)
	var conformedFileDef:String = conformExtension(fileName);//comment: updated 17.11.2008 removed the typo
	tmpArr.push(conformedFileDef);
	//Create a new file object giving as input our new path with conformed file extension
	var conformedFile:File = new File("file:///" + tmpArr.join(File.separator));
	//Make save
	var stream:FileStream = new FileStream();
	stream.open(conformedFile, FileMode.WRITE);
	stream.writeUTFBytes("demo demo demo demo demo demo demo demo demo");
	stream.close();
}
private function conformExtension(fileDef:String):String
{
	var fileExtension:String = fileDef.split(".")[1];
	for each(var it:String in VALID_EXTENSIONS_LIST){
		if( fileExtension == it)
			return fileDef;

	}
	return fileDef.split(".")[0] + "." + MY_DEFAULT_EXTENSION;
}

Feel free to add any comment!

spacer Adobe AIR tips serie: browseForSave set default file extension and validate/modify. image

Export character and paragraph styles for Flex/Flash as css from Indesign

September 22nd, 2008 | By Cedric

postImage 01short Export character and paragraph styles for Flex/Flash as css from Indesign image
spacer Export character and paragraph styles for Flex/Flash as css from Indesign image

Problematic

Sometimes they would occur situations when you have to convert a set of styles and paragraphs made with Adobe Indesign. In fact they are not much solution available, but epub and Digital Edition can come to your rescue…

Solution available

Paragraphs Styles and Characters Styles set in Adobe Indesign CS3’s documents or books are very efficiently converted into a .css style sheet.
This .css file works great with your Flex projects because Digital Edition is build on Flex, so this conversion makes it just perfectly fit Flex css requirements.
So it is a good temporary way to fill the gap between designers and developers in Flex 2-3 products workflow, before Thermo and XFL export are made available.
It is also an excellent generic solution to export .css files from Indesign CS3 styles.

How to

28 ps menu Export character and paragraph styles for Flex/Flash as css from Indesign image

Steps to get the css file.

0: In Indesign put text field with text to which you applied all styles that you want to export and select text fields
1: In Indesign choose File CrossMedia-export
2: Rename the exported .epub file into .zip
3: Decompress it
4: Open folder containing decompressed files and open subfolder: OEBPS/
5: Get the template .css file.

As you can see it put even fonts information, for example: @font-face {
font-family: “Corbel”;
font-style: normal;
font-weight: normal;
src:url(Fonts/CORBEL.TTF); /*note that only opentype fonts are officially supported*/
}

Only font information in the css file are usable in a Flex project, the “embedded encrypted font files” (OEBPS/Fonts) used by Digital Edition is not usable by Flex because they are restricted/binded to your DE document ):

More information about .epub and related formats: http://blogs.adobe.com/digitaleditions/indesign-epub.html
You should check out Live Docs on export epub
You should also install and test Adobe Digital Edition (AIR Installer), this is a beautifull piece of software.