Articles Tagged: tutorials

flash platform flex air flash tutorials, code samples, demo, references

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

November 17th, 2008 | By Cedric Madelaine

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

Papervision3D Demo: move Pivot-Axis only

June 20th, 2008 | By Cedric Madelaine

022 pivot3d Papervision3D Demo: move Pivot Axis only  image
spacer Papervision3D Demo: move Pivot Axis only  image
Free pivot!
If you are familiar with 3d modelling softwares you are used to “pivot only” manipulation. It allows pivots to be aligned within a 3d object depending of min, center, max,(or free) on x,y,z axis relative to its corresponding object. It is crucial to manipulate and visualise pivot location especially when manipulating and animating complex objects or doing advanced animations. I miss this in Papervision3D, since the first time I put hands on it one year and a half ago.

Manipulating Pivot in Papervision3d

(using Public Alpha 2.0 – Great White (24.03.08)) To change pivot location of a DisplayObject3D, you need to take the problem reverse. The pivot is not an independant object which can be manipulated freely within an object, you need to use a wrapper DisplayObject3D used only as a base pivot and to which you will add other DisplayObject3D. You will create a container DisplayerObject3D and then move your DisplayObject3D inside it. The pivot remains in the center of your container/wrapper.
For example, cube A, the pivot is by default centered on x,y,z in Papervision3D. You’d like that the pivot of cube A is placed at the front top corner (x:0,y:0,z:0). Theorical solution(cf 3d softwares): move the pivot
only within the object. Real Solution(Pv3d): you add cube A to a new DisplayObject3D and then move your cube A of half its width, height and length.

The demo

I made a simple PivotObject class which represent visually a pivot point and a pivot group allowing positioning pivot within a group like in 3d modelling softwares.
The concept is to use a DisplayObject3D aka a “pivot group”. A pivot 3d object is built as a temporary visualisation helper at development time, afterwards it is removed at production time. I have set up this demo as a proof of concept. I am going to publish corresponding classes as soon as I have cleaned everything. So stay tuned!


spacer Papervision3D Demo: move Pivot Axis only  image
022 preview Papervision3D Demo: move Pivot Axis only  image
spacer Papervision3D Demo: move Pivot Axis only  image