Archive

Posts Tagged ‘flex’

Loading TIFF Images in Flex and AIR

May 30th, 2012 Adam 1 comment

Flex and Actionscript doesn’t handle TIFF images inherently. However, there is a library of TIFF decoding functions that I found buried in the interwebs (Big thanks to C.T. Yeung).

I made a few slight modifications because it wasn’t working when I downloaded it from Yeung. Speaking of which, this decoder doesn’t support TIFF compression. So you can’t load LZW or ZIP compressed TIFFs.

Here are the modified library files.

Here is how you would load a TIFF in Flex:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import mx.controls.Alert;
import com.utils.Tiff.TIFF6Decoder;
 
private var tiffDecoder:TIFF6Decoder;
private var byteArray:ByteArray;
 
private function loadFile():void{
	var request:URLRequest = new URLRequest(
		"http://test.url.com/sample.tif"
	);
	var urlLoader:URLLoader = new URLLoader(request);
 
	urlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
	urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
	urlLoader.load(request);
}
 
private function onLoadComplete(e:Event):void{
	byteArray = e.target.data;
 
	tiffDecoder = new TIFF6Decoder();
	if(tiffDecoder.decode(byteArray))
		img.source = new Bitmap(tiffDecoder.bitmapData);
	else 
		Alert.show("Failed TIFF decoding");
}

Here is an AIR example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import mx.controls.Alert;
import com.Tiff.TIFF6Decoder;
 
private var tiffDecoder:TIFF6Decoder;
private var fileStream:FileStream;
 
private function loadFile():void{
	var tiffFile:File = new File("C:/tiffs/sample.tif");
	fileStream = new FileStream();
	fileStream.addEventListener(Event.COMPLETE, onLoadComplete);
	fileStream.openAsync(tiffFile, FileMode.READ);
}
 
private function onLoadComplete(e:Event):void{
	var byteArray:ByteArray = new ByteArray();
	fileStream.readBytes(byteArray);
	fileStream.close();
 
	tiffDecoder = new TIFF6Decoder();
	if(tiffDecoder.decode(byteArray))
		img.source = new Bitmap(tiffDecoder.bitmapData);
	else 
		Alert.show("Failed TIFF decoding");
}
Categories: actionscript, air, flex Tags: , , , ,

Improving the default Spark skins in Flex 4

April 13th, 2010 Adam 3 comments

I don’t know about everyone else, but I think the default component skins in Flex 4 are a big mistake. Well, let me be clear: I know the new Spark components are now easier to customize. And that is great. I am all for improving customization and usability. But some people don’t like skinning the default components! Would it have been so hard to improve the functionality while still making the default skins pretty? Like the Halo skins from Flex 3? One of the best things about Flex 3 is that I could just pop in a bunch of UI elements and it would be a great-looking application right out of the box. With the addition of Spark, I am now forced to customize the look of the components.

So, for starters, I’ve corrected one of the main faults, which is the font. I found that simply changing the default Spark font, it makes a big impact. All you have to do is add the following style code to your application:

1
2
3
4
5
6
7
<fx:Style>
	@namespace s "library://ns.adobe.com/flex/spark";
	s|Application{
		font-family: "Verdana";
		font-size: 10;
	}
</fx:Style>

As you can see in the example below, the left UI is the default skin. The right UI is with this minor font change. I think it makes a big difference:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

I’m sure there are some other things I can do globally, to make Spark a little better-looking out of the box. The font is just a small step in the right direction.


Another Method

 
Now, I will say that there’s another method of forcing the compiler to use the Halo skins. I don’t like this method though. For starters, the proper skins don’t show up in Design View. Also there are a few syntax issues with mixing the skins. Having said that, if you want to go that route, you can: Go to your project properties, then go to Flex Compiler, and append this text to the Additional compiler arguments:

    -theme=${flexlib}/themes/Halo/halo.swc

DataGrid Row Height and Padding

March 19th, 2010 Adam 3 comments

If you’ve ever tried to lower the rowHeight property of a DataGrid in Flex, you have probably noticed that if you lower the height too much, your text will get cut-off at the bottom. I’ve tried a number of solutions to correct this problem, but this one seems to be the best.

There are two properties addressed here: leading and paddingBottom.

leading: controls the bottom padding of the DataGrid header only.
paddingBottom: controls the bottom padding for all the DataGrid rows, AND the DataGrid header.

Thus, the solution is to lower the value for paddingBottom, and compensate by increasing the leading value.

for example:

1
<mx:DataGrid rowHeight="18" leading="4" paddingBottom="0">

By default, both of those settings are 2.

See the example below:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
The rowHeight property of both DataGrid controls are set by the slider at the bottom. The DataGrid on the left has default values for leading (2) and paddingBottom (also 2). Those properties for the DataGrid on the right is controlled by the sliders.