on Jun 25th, 2009RIA with Flex and Java using Weborb for Java

What fits better? LCDS? LiveCycle Data Services for real Java enabled logical business and keep you pushing the limits of your RIA?

I got this question earlier this month after my involvement in a medium scale application built-in Flex front and Java on server side.

Doing the right decision requires you as much as needed and comparing a lot of products available in the market and see those features I decided to use WebOrb for Java due to some comparatives that are really awesome.
One of them is the native DTO/DAO code generation and CRUD, which saves a lot of time doing repetitive tasks.

And who did or are doing kind of Application, might knows what I’m talking. The only -2 points of credit for WebOrb is the JMS integration and Datapaging documentation. Not good so far and you have to discover yourself how it works.

Aside this problem the product works smooth in only CPU and uses 20% of PC. Nicely done.

If you wanna to compare with others, I found in my researches at Midnight coders blog a list-base comparation features that let me to test the weborb and see if I could use in the App.

Check out!

on May 22nd, 2009Doing Flex 3 components in actionscript the right way

One of the big problems I had in the past was developing kick ass components in actionscript format, where you see by proven simple basic component done for Google Maps.
Most of applications I did before was using only mxml format and this is straight forward way that 9 of 10 Flex developers does in usual ways.
I was doing pretty well, but for sure if you’re trying to get better and better as a developer you see that a long way to do and write stuffs like bytearray.org, mchambers, gskinner. Most of theses developers love and breath the development process, respecting the framework and the way they flow.

Six months ago I had this as goal, achieve a development senior level for custom components in actionscript format. The best way to do that was reading the Flex SDK source code, and see how I could learn from them. I must say you to not do that right now if you don’t have a big experience in Flex development, has a lot of way to go.

It’s hard enough to learn this path and get a level of that. The pursuit of happiness was very clear for me after three months of study and internal tests, samples. I personally don’t like read I most enjoy see in action examples of some framework then I read later the docs.

In fact was hard months, because I just got 3 or 2 hours a day to study. I needed as anyone needs to work and put grant the food for home. And some times I would think in give up and keep going doing mxml code and some little utility classes. But when everytime I saw a bug logged in the Flex bug base and example of work from those guys I mentioned earlier. I draw back and keeping fire to learn theses process.

There’s a bunch of information out there today after those 5 years of working with Flex framework and for sure this might be one of the best time to learn Flex and even getting deep to learn from the source. Many resources, slides, samples you can find on internet that are better worth then the livedocs, where today in my point of view are getting better and better with days to come.(Randy is doing a great job there).

But you’re very lucky today after I saw a simple, direct to point white paper to learn the process of doing components in Flex. Kudos to James Polanco and Aaron Pedersen . They’ve released a documentation that is worth to read for any developer that reads this blog or works with Flex development, with simple words any dummy developer that has a minimum of 6 months of experience in Flex framework can learn on the component live cycle in Flex.

Here’s the direct link for the PDF file where you can print and read in home even if you’re not in front of PC or MAC(who knows?!).

For others document I’ve collected before when I was learning this is the comprehensive list of sources I’ve got to kick ass in as3 components for Flex, in a TOP of 10 resources sites:

1. Slide share collection of slides that get you ahead in this field.
2. Live Docs on Advanced Flex Components
3. For who without free time to learn and want learn fast.
4. Like a to-do-check-list for any developer who wants to check your component before use it.

5. A nice review that was my second text on learning.
6. A nice diagram and complete diagram of workflow where you can print and never forgot.
7.Implementing accessibility on to your flex components.
8. How to write non-visual Flex components.
9. A nice one read for non-visual flex components.
10. And the last but no least a great white paper of doing Flex 3 Components int he right way. (This is recent and didn’t had the lucky to read in that time).

Enforce your development skills with this little list, has a lot of other resources like Jessen Warden blog and gets a lot of boiler list of tips and tricks for flash platform developers, google code, with a 1.333 projects tags as Flex and you save time in light up new ideas of components, check that before.

Hope you enjoy.

on May 15th, 2009Hacking asDoc

I found a very utility undocumented params to be used in asDoc before itself generate the docs format for you.

Hacking asDoc
If you intend to learn more about your generated docs this will be a plus to understand how to approach to it.

on Apr 27th, 2009Hacking BlazeDS to work with Google App-Engine for Java

Yes, After among those previous blog posts I really looking forward to see if BlazeDS will works in GAE/J. But for my limited Java knowledge I could not accomplished any hack. Luckily Martin Zoldano drop-me a line today morning to tell me that he hacked BlazeDS to put it work with GAE/J.

Check out here at his webblog.

For sure is a good example of community efforts. Kudos to you Martin.

on Apr 21st, 2009GraniteDS answers to GAE/J, will it play?

GraniteDS is fully working with GAE/J according to their blog post.

http://graniteds.blogspot.com/2009/04/graniteds-20-on-google-app-engine.html

Quick Post, but you should read the aspects of functionality and pretty awesome see the community reactions against the white list of Google classes and putting complex serializations to work.
For sure GraniteDS works nice like Weborb for Java. No sign of light from BlazeDS team or even blog post from James Ward that I blogged before.

on Apr 18th, 2009GAE with Java and AMF3 will play?

Sure, again the guys at midnight coders are doing a great effort to put weborb for Java in every java container out there. They did in the past supporting weborb for java in Glassfish now supports amf3 transcriptions not only amf3 but messaging too.

I was following Mark , and after some skype talks and he promised to blog. I’ve tested, deployed and worked. As Mark explains in this blog post, he had to adapt the product to support the white list classes of GAE but worked, other features you see in Weborb for java still not work, but hope they find a way better to reproduce the steps and let other developers to adapt too.

Enjoy it!

on Apr 11th, 2009Will BlazeDS play in GAE Java?

Right now is almost impossible. But I was following James Ward on Twitter and he said in a twitt that he deployed sucessfully the BlazeDS in AppEngine.
I’ve tried today in my day off and didn’t get to work. And I’m not alone with this problem. Few people, people are having the same problem.

For sure James would tell to the community how he did that. Even, OpenAMF, GraniteDS, BlazeDS and WebOrb for Java isn’t available to GAE. Hope the White-list will include the packages to support. Otherwise the EC2 will still rocks.

AMF0 or AMF3 still doesn’t support right now for Java Apps. You can only play with HTTPServices in Flex side. Sooner this could change.

on Feb 26th, 2009Hacking BlazeDS to work with GlassFish

The BlazeDS officially doesn’t support Glassfish container for JEE applications, and many people get troubles or problem to accomplish this challenge. That’s a tip to think about it, “The open-source java community knows that them can contribute to BlazeDS?”. Anyway isn’t easy to find a solution that work out. I did mine reading theses two blog post here and here.

It’s a good hack by the way, but make sure that this hack is only for development propose, if you’re trying to put in production, you better bet your Architect.

on Feb 25th, 2009#9 Flex Hack – Filtering a data collection without filterFunction

This hack is about filtering data collection into control.
Some weeks ago a user of Flex-Brazil list asked how to apply filter directly on datagrid which gets the same data source. There are a great and very useful hack to apply filter function directly to data source not in the control, you can stop by here.
Okay, once you know that everything in Flash Player is Object and every object has own properties, it’s so easy to manipulate those objects, let’s take a look.

Level: Beginner.

So, what I used is just a little utility method to filter objects before apply to the control, it works with many cases, like XMLList, XMLListCollection, Array, and many UI controls that handle with data.

Here’s the method utility to make the magic:

		public function applyFilter(rule:String,col:ArrayCollection):ArrayCollection
		{
			var newArr:ArrayCollection= new ArrayCollection();
			if(col !=null){
				for each(var obj:Object in col){
					if(obj.level == rule){
						newArr.addItem(obj);
					}
				}
			}
			return newArr;
		}

I create a simple loosely temp array collection to catch all data that fits on the rule, the obj.level where level is the property I want to watch.
Doing that you will just need to some event-drive model to the collection itself and control logic workflow. The all things are very known from you.

Here’s the full code sample for this Hack.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
<mx:Script>
	<![CDATA[
		import flash.sampler.NewObjectSample;
		import mx.events.CollectionEvent;
 		import mx.collections.ArrayCollection;
 
		public function applyFilter(rule:String,col:ArrayCollection):ArrayCollection
		{
			var newArr:ArrayCollection= new ArrayCollection();
			if(col !=null){
				for each (var obj:Object in col){
					if(obj.level == rule){
						newArr.addItem(obj);
					}
				}
			}
			return newArr;
		}
		[Bindable]private var o:Object;
		private var change:Boolean = false;
		private function addGuru():void
		{
			if(guruname.text.length>0){
				o = new Object();
				o.name = guruname.text;
				o.level = gurulevel.selectedLabel;
				someflexgurusCollection.addItem(o);
				change =true;
				someflexgurusCollection.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
			}
 
		}
 
		private function updateProviders(event:CollectionEvent):void
		{
			if(change){
			dvDG.dataProvider = applyFilter('Dark Vader',someflexgurusCollection);
			cwDG.dataProvider = applyFilter('Cowboy',someflexgurusCollection);
			jdDG.dataProvider = applyFilter('Jedi',someflexgurusCollection);
			nbDG.dataProvider = applyFilter('Newbie',someflexgurusCollection);
			}
		}
	]]>
</mx:Script>
<mx:ArrayCollection collectionChange="updateProviders(event)" id="someflexgurusCollection">
		<mx:Object name="Rich Tretola" level="Jedi"/>
		<mx:Object name="Matt Chotin" level="Dark Vader"/>
		<mx:Object name="Ted Patrick" level="Jedi"/>
		<mx:Object name="Mark MidNight" level="Dark Vader"/>
		<mx:Object name="Jesse Warden" level="Dark Vader"/>
		<mx:Object name="James Ward" level="Cowboy"/>
		<mx:Object name="Joe Lott" level="Jedi"/>
		<mx:Object name="Marco Casario" level="Cowboy"/>
		<mx:Object name="Abdul Qabiz" level="Jedi"/>
		<mx:Object name="Igor Costa" level="Newbie"/>
</mx:ArrayCollection>
 
	<mx:Button x="10" y="126" label="Add" click="addGuru()"/>
	<mx:DataGrid id="dvDG" x="292" y="48" dataProvider="{applyFilter('Dark Vader',someflexgurusCollection)}">
		<mx:columns>
			<mx:DataGridColumn headerText="Guru Name" dataField="name"/>
			<mx:DataGridColumn headerText="Guru Level" dataField="level"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:DataGrid id="cwDG" x="292" y="240" dataProvider="{applyFilter('Cowboy',someflexgurusCollection)}">
		<mx:columns>
			<mx:DataGridColumn headerText="Guru Name" dataField="name"/>
			<mx:DataGridColumn headerText="Guru Level" dataField="level"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:DataGrid id="jdDG" dataProvider="{applyFilter('Jedi',someflexgurusCollection)}" x="502" y="48">
		<mx:columns>
			<mx:DataGridColumn headerText="Guru Name" dataField="name"/>
			<mx:DataGridColumn headerText="Guru Level" dataField="level"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:DataGrid id="nbDG" dataProvider="{applyFilter('Newbie',someflexgurusCollection)}" x="502" y="240">
		<mx:columns>
			<mx:DataGridColumn headerText="Guru Name" dataField="name"/>
			<mx:DataGridColumn headerText="Guru Level" dataField="level"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:Label x="292" y="21" text="Just Dark Vaders" fontWeight="bold" fontSize="11"/>
	<mx:Label x="292" y="213" text="Just CowBoys" fontWeight="bold" fontSize="11"/>
	<mx:Form x="10" y="36">
		<mx:FormItem label="Name">
			<mx:TextInput id="guruname"/>
		</mx:FormItem>
		<mx:FormItem label="Level">
			<mx:ComboBox id="gurulevel">
					<mx:dataProvider>
							<mx:String>Dark Vader</mx:String>
							<mx:String>Cowboy</mx:String>
							<mx:String>Jedi</mx:String>
							<mx:String>Newbie</mx:String>
					</mx:dataProvider>
			</mx:ComboBox>
		</mx:FormItem>
	</mx:Form>
	<mx:Label x="10" y="10" text="Add New Flex Guru" fontWeight="bold" fontSize="18"/>
	<mx:Label x="501" y="21" text="Just Jedi" fontWeight="bold" fontSize="11"/>
	<mx:Label x="502" y="213" text="Just Newbie" fontWeight="bold" fontSize="11"/>
</mx:Application>

on Feb 3rd, 2009SWFTools (pdf2swf) to properly work with Flex

It’s hype, there’s no word to describe how to involve and open-source command-line tool to transcode from pdf to swf file and get it right work with Flex.
So, I googled a lot yesterday and today morning, and didn’t find any relevance information on this field. I just saw a collection of developers getting problem to put it to work. For sure it’s a little hard work to put it in right to work.
The problem took me attention because we got a job from a start-up company that does document of any type and convert into a swf. Of course that you should put more effort to accomplish bunch things like Scribd does.
To help theses unlucky devs out there follow the steps of this tutorial bellow and 20% of your problem will solve, bet if solves 100% isn’t?

Get Start

  • Download the last version of SWFTools and put in the root of your HD access mine was (C:\swftools)
  • Grab some pdf you want to convert into swf and start transcode.
  • Open up your Prompt command and goes to the path where you put your SWFTools

To run the pdf to swf converter you just type :

C:\SWFTools\pdf2swf originalfile.pdf -o newfile.swf

This is automatically converts your pdf into something easy format like swf and ready to Flash Player.

The pdf2swf has many options see them bellow:

  • −h, −−help Print short help message and exit
  • −V, −−version Print version info and exit
  • −o, −−output file.swf will Go into a seperate file.
  • −p, −−pages range Ex:3-5,10-12
  • −P, −−password password Use password for deciphering the pdf.
  • −v, −−verbose Be verbose. Use more than one -v for greater effect.
  • −z, −−zlib The resulting SWF will not be playable in browsers with Flash Plugins 5 and below!
  • −i, −−ignore SWF files a little bit smaller, but it may also cause the images in the pdf to look funny.
  • −j, −−jpegquality quality Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)
  • −s, −−set param=value Set a SWF encoder specific parameter. See pdf2swf -s help for more information.
  • −w, −−samewindow When clicked on, the page they point to will be opened in the window the SWF is displayed.
  • −t, −−stop The resulting SWF file will not turn pages automatically.
  • −T, −−flashversion num Set Flash Version in the SWF header to num.
  • −F, −−fontdir directory Add directory to the font search path.
  • −b, −−defaultviewer Therefore the swf file will be “browseable”, i.e. display some buttons for turning pages.
    The viewer swf to be used is determined by a symlink named “default_viewer.swf” in
    the swftools data directory.
  • −l, −−defaultloader The loader swf to be used is determined by a symlink named “default_loader.swf” in
    the swftools data directory.
  • −B, −−viewer filename See http://www.quiss.org/swftools/pdf2swf_usage.html for information on how to create your own viewers.
  • −L, −−preloader filename filename is an arbitrary swf animation.
  • −q, −−quiet Suppress normal messages. Use -qq to suppress warnings, also.
  • −S, −−shapes Don’t use SWF Fonts, but store everything as shape.
  • −f, −−fonts Store full fonts in SWF. (Don’t reduce to used characters).
  • −G, −−flatten This usually makes the file faster to render and also usually smaller, but will increase
    conversion time.
  • −I, −−info Don’t do actual conversion, just display a list of all pages in the PDF.
  • −Q, −−maxtime n Abort conversion after n seconds. Only available on Unix.

Converting in the right way

The creators of SWFTools claim that you can export in AVM2, but in fact the Flash Player only recognize the header in the swf, not the document structure, which for Flex DOM is fundamental to understand.

Ok, How I convert mine with options?

I used ANT to do stuff things for conventions since I don’t want to re-type always I have a new PDF to convert in house. But simplifying it worked for me this command line argument.

C:\SWFTOOLS>pdf2swf -z -t sourceFile.pdf -o OutputFile.swf

That’s right, you have your swf file converted and running, What was done? I insert a stop action in each frame because this cause the swf to play each frame. Also I compacted the file using gzip to decrease the size, same as Scribd does.

Flex side

Create a new Flex project, name it as you wish. After that you might be think it’s simple we can load it using SWFLoader, but you will have problems to control and Flex will understand that this file is just as asset not as a component. To work with that, you have various options like, Loader, ByteLoader, ModuleLoader and BulkLoader. To load into Flex and given you a certain to control it.

My solution was simple, as I known that pdf2swf just give me swf in head with 8 version, I can manage a instance and place where I wish. That was easy, but what about Flex to control from Flash 5,6,7,8, both have their own way of render and work. To accomplished that I googled a little, because I knew it that some one should have fight this problem before and for lucky I found this class that kick ass problem. See class bellow:

package
{
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.Event;
	import flash.utils.ByteArray;
	import flash.utils.Endian;
	import flash.errors.EOFError; 

	public class ForcibleLoader
	{
		public function ForcibleLoader(loader:Loader)
		{
			this.loader = loader;
			_stream = new URLStream();
			_stream.addEventListener(Event.COMPLETE, completeHandler);
			_stream.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			_stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
		}
		private var _loader:Loader;
		public var _stream:URLStream;
		public function get loader():Loader
		{
			return _loader;
		}
		public function set loader(value:Loader):void
		{
			_loader = value;
		}
		public function load(request:URLRequest):void
		{
			_stream.load(request);
		}
		private function completeHandler(event:Event):void
		{
			var inputBytes:ByteArray = new ByteArray();
			_stream.readBytes(inputBytes);
			_stream.close();
			inputBytes.endian = Endian.LITTLE_ENDIAN;
			if (isCompressed(inputBytes)) {
				uncompress(inputBytes);
			}
			var version:uint = uint(inputBytes[3]);
			if (version <= 10) {
				if (version == 8 || version == 9 || version == 10){
					flagSWF9Bit(inputBytes);
				}
				else if (version <= 7) {
					insertFileAttributesTag(inputBytes);
				}
				updateVersion(inputBytes, 9);
			}
			loader.loadBytes(inputBytes);
		}
		private function isCompressed(bytes:ByteArray):Boolean
		{
			return bytes[0] == 0x43;
		}
		private function uncompress(bytes:ByteArray):void
		{
			var cBytes:ByteArray = new ByteArray();
			cBytes.writeBytes(bytes, 8);
			bytes.length = 8;
			bytes.position = 8;
			cBytes.uncompress();
			bytes.writeBytes(cBytes);
			bytes[0] = 0x46;
			cBytes.length = 0;
		}
		private function getBodyPosition(bytes:ByteArray):uint
		{
			var result:uint = 0;
			result += 3; // FWS/CWS
			result += 1; // version(byte)
			result += 4; // length(32bit-uint)
			var rectNBits:uint = bytes[result] >>> 3;
			result += (5 + rectNBits * 4) / 8; // stage(rect)
			result += 2;
			result += 1; // frameRate(byte)
			result += 2; // totalFrames(16bit-uint)
			return result;
		}
		private function findFileAttributesPosition(offset:uint, bytes:ByteArray):uint
		{
			bytes.position = offset;
			try {
				for (;;) {
					var byte:uint = bytes.readShort();
					var tag:uint = byte >>> 6;
					if (tag == 69) {
						return bytes.position - 2;
					}
					var length:uint = byte & 0x3f;
					if (length == 0x3f) {
						length = bytes.readInt();
					}
					bytes.position += length;
				}
			}
			catch (e:EOFError) {
			}
			return NaN;
		}
		private function flagSWF9Bit(bytes:ByteArray):void
		{
			var pos:uint = findFileAttributesPosition(getBodyPosition(bytes), bytes);
			if (!isNaN(pos)) {
				bytes[pos + 2] |= 0x08;
			}
		}
		private function insertFileAttributesTag(bytes:ByteArray):void
		{
			var pos:uint = getBodyPosition(bytes);
			var afterBytes:ByteArray = new ByteArray();
			afterBytes.writeBytes(bytes, pos);
			bytes.length = pos;
			bytes.position = pos;
			bytes.writeByte(0x44);
			bytes.writeByte(0x11);
			bytes.writeByte(0x08);
			bytes.writeByte(0x00);
			bytes.writeByte(0x00);
			bytes.writeByte(0x00);
			bytes.writeBytes(afterBytes);
			afterBytes.length = 0;
		}
		private function updateVersion(bytes:ByteArray, version:uint):void
		{
			bytes[3] = version;
		}
		private function ioErrorHandler(event:IOErrorEvent):void
		{
			loader.contentLoaderInfo.dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
		}
		private function securityErrorHandler(event:SecurityErrorEvent):void
		{
			loader.contentLoaderInfo.dispatchEvent(new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR));
		}
	}
}

With this face off, you can handle quickly in Flex, I’ve built an application example. And for your own risk you can implement, share more functionalities, more controls, anyaway, you’re free for it.

Here’s the Main application.





		[Event(name="PDFComplete",type="flash.events.Event")]


	
		
	
	
			
			
			
				
			
			

You see, I didn’t used the SWFLoader of Flex, as explained before, I prefer to handle in diffrent way.
This application is simple, has some buggies (littles), but in general, just figure you out how to do such thing.

Missing things you could implement, TextSearch, Thumbnail generation from loaded swf to pages.

Download the FULL source code of this application here. Wanna see example of running, you have to download and it’s included. Because I didn’t put effort in secury sandbox levels in it.

Links of my researches: