AIR, , , , " />

FlashPlatformist
Articles, Information, News, & Tutorials for Adobe Flash Platform Developers and Architects

Using the Zend Framework to take some wind out of AIR

If you have worked at length with the Zend framework for PHP, you already know that it can do just about anything you could possibly need it to. With that in mind, it is not surprising to find that Zend will talk to almost any web service available, and it’s all built right into the framework. This is ideal when you want to build a truly “thin” client, where the code for the user interface is actually specific to the user interface and the business logic is abstracted into an entirely separate layer. This allows for maximum code reuse as well as multi-tier enterprise scalability and ease of deployment.

In some respects, the Internet cursed the enterprise because it caused developers to abandon rich, client-side user interfaces in favor of advantages such as version management that they had on local networks. The Adobe Integrated Runtime (AIR) is a desktop application development tool that is conducive to enterprise software development simply for the fact that the only code that needs to reside within the client application is that which pertains directly to the user interface. Therefore, a powerful language and framework like PHP and Zend can hold the business logic for server-side processing before handing the data off to the client. When combined with the Action Message Format (AMF) protocol for rapid data transfer, you end up with a seriously powerful enterprise-grade desktop application that’s hooked right into the Internet.

This brings up an important point: just because a code library or Software Development Kit (SDK) already exists for ActionScript that does the same exact thing as the Zend framework’s implementation, does not necessarily mean that it should always be used. Nine times out of ten, the users of your Flex or AIR application will be pleasantly surprised to find how smoothly it runs when you optimize your database and cache the information on the server, while using AMF or RTMP to transfer compressed, binary data packets between client and server.
Some may argue that this will increase costs associated with bandwidth consumption in an enterprise environment. This is true. At the same time, AMF is the most efficient protocol standard available right now, and the cost to the company is a fraction of the cost compared to using REST or SOAP.

Enterprises waste a lot more money by scaling hardware in clustered network infrastructures rather than moving to Cloud-based solutions right now anyway, so the credibility of that argument is questionable.

Possibly Related Posts:



Posted by Dan Orlando on August 23rd, 2009 :: Filed under Enterprise Flex
Tags :: , , , ,

Handling Advanced Item Renderers for List-based Components in Flex and AIR

Recently I was charged with the responsibility of creating a very complex visual interface in Flex that looks more like something you’d expect to see built with Flash because of the animation and 3D effects. Flex was clearly the better choice for developing this piece of the application, but I learned a number of things regarding the limitations of Item Renderers, particularly those having to do with the Flex TileList component.

The Requirement
The primarily component needed to display a tiled list of objects that represented a group of media objects. Each item renderer in the TileList had to have 3 images, each representing a different piece of media, and when the user hovered over one of the items, a parallel effect that combined one Zoom effect, 3 Move effects, and 2 Rotate effects. The top image ultimately needed to zoom in and have a DropShadow filter applied to it to give it a 3D-like effect, and the middle and bottom images needed to fan out to the left and right using the combined rotate and move effects on each one.

Getting the Data
Getting the data in the first place was a task in and of itself. My first several iterations of the code involved a lot of looping through the massive collection of media “packages” that is returned from the server, in order to get the sets of preview images from each media package object that i needed for the item renderers. I eventually came to realize that I could cut the amount of code I was using for this thing into a fraction by simply using the standard , with the data provider set to this massive collection of objects being sent from the server. This, however, required a complex and well-planned item renderer component written in ActionScript. The item renderer component extended the Flex TileListItemRenderer class and implemented the IListItemRenderer and IDropInListItemRenderer interfaces.

In this solution, each Item Renderer automatically receives one of the media package objects from the large collection that is sent from the server. This functionality is already built into the ListBase, so all I needed to do was find the array of images that from the object, then loop through the array and determine the “role” that each image should play in the item renderer (eg. top image, middle image, or bottom image) and discard anything else that I didnt need.

The Major Problem
The big problem I ran into, was the fact that the complicated effects that i built for the mouse over and mouse out required the item renderer display object to overlap the surrounding display objects in the tilelist. This, unfortunately, was completely impossible, and after studying all of the classes that TileList is extended from and how the TileList component automatically lays out the objects within the list, I found that it was impossible to prevent clipping of the images from occurring when the effects were generated.

The Quick-and-Dirty Solution
Due to time constraints, I needed a solution that i could implement quickly, and as long as it looked pretty, we were ok. In other words, an elegant hybrid component was simply not an option. I should also note that other possible solutions, like using a repeater with a Grid container, were not options either for reasons that are beyond the scope of this article/blog.

I created an mxml component based on the Canvas container that took 3 images as properties, dropped shadow filters on the images and included 2 parallel effects for the over and the out events. When the mouse over (or mouse out) occurs on an item renderer, this additional component that holds the effects is added to the stage with this.parentApplication.addChild(_effectContainer). So essentially, a new iteration of the item renderer that fired the event is being created as an overlay and the effect can then play and is free to run over any display objects in its way, since it is ultimately automatically added to the stage with an index that is higher than all other display objects on the stage.

In order to get this right however, the positioning of this canvas has to be pristine. In other words, when the new child (the effect container) with the duplicated images is added to the stage, the x,y coordinates of the initial state of the image stack (which is with only the top image displayed, assuming the other two images are of the same size and have the same x,y values) must be EXACTLY the same as the x,y position of the item renderer that generated the new instance of the display object responsible for displaying the effects. This ultimately makes it look as if the animation is playing on the actual item renderer, when in fact the item renderer is merely still lying directly beneath it’s double.

To be honest, the final product is pretty bad-ass and gives a flash-like quality to a data-driven Flex UI component. However, this is not the most elegant solution, as the ideal thing would be to create a hybrid TileList-like component that includes DYNAMIC layout constraints on each item renderer. Therefore, the component would automatically recognize that a display object inside of one of the item renderers was pushing on the boundaries of the container that was allocated to it and resize itself automatically until the animation stopped by placing calling super.invalidateProperties or super.updateDisplayList on the UIComponent class on each ENTER_FRAME event until the internal display objects of the item renderers stopped pushing on the layout bounds. There is a little caveat to this however, and that is – resizing the layout constraints of the item renderer must NOT change the layout of the component as you would expect. In other words, we could suspect that implementing such functionality into a hybrid TileList component would by default push the other item renderers around to compensate for the renderer that was resized. This assumes however, that we do NOT want the item renderer to overlap the surrounding renderers, which in the case of this requirement, is untrue. When the user rolls off the item renderer’s effect double, the rollover animation should basically play in reverse and then simply remove itself from the parent’s display list. Thus, the original layout of the TileList is never changed by the effects rendering.

My feeling is that we will build such a component eventually, probably for a future version of this application, but we’ve got a deadline to meet right now, and sometimes making the right business decision means quick and dirty is the answer.

As much as I’d love to actually show the code for this view state that I have described here, I must respect certain nondisclosure and intellectual property rights and restrictions considering the nature of the application we are building. However, I will provide a generalized code example of a specific element described in this article if there is something in particular that you would like to understand in greater detail by actually seeing it. I am very quick to respond to comments, so feel free to ask if there is anything in particular you would like to see.

Possibly Related Posts:



Posted by Dan Orlando on November 10th, 2008 :: Filed under Tutorials
Tags :: , , , , ,

New Technology for ActionScript Data Communications

I spent a large portion of this week learning a new technology based on a collaboration between Adobe and Zend Technologies for data communications and an unified workflow for PHP RIA developers. My assignment was to write up an article/tutorial on implementing the new technology into Flex/AIR applications. Since it is a new technology that has yet to be released to the public, the setup and configuration process was naturally a bit daunting. After I got it up and running though, I was pretty impressed with what this new technology offers. The article is set to be published initially at OnLamp.com immediately following the public announcement and release of this new technology. I will provide more details and additional information on getting up and running with this new technology here, but for now, mum’s the word.  :-)

Possibly Related Posts:



Posted by Dan Orlando on October 10th, 2008 :: Filed under General
Tags :: , , , , ,

Layering Code for Large-Scale Flex, Air, and Actionscript 3.0 Applications

With all of the books that I’ve read on Flex and Actionscript 3.0 development, I find it interesting that none of them go into detail about the organizational structure of an enterprise level RIA application built with Flex. Perhaps Flex is still too immature and has not really evolved enough yet to write on such topics. Nonetheless, that is exactly what we are going to discuss in this article. More specifically, we will go into detail on how one might want to structure an RIA application that he or she expects to grow very large in size. In other words, we will pay particular attention to designing an application foundation that is scalable in nature.

In order to cultivate a development environment that caters to ultimate scalability, we must start by separating our code into clearly defined layers. By layering our code, we are able to entertain a high level of abstraction in the logic. Most RIA applications are split into 3 initial layers by nature: the server side logic and database, the client side logic (and database also if we’re working with an AIR app that uses a client-side DB as well), and the medium that is used for client-server communication. Here are two examples that come straight from the two big projects I am currently part of:

Project 1
Client-side: AIR desktop app & SQLlite
Server-side: Java/Jboss with MySql Enterprise
Client-server communication: Custom Java REST service and JVM (Java Messaging Service)

Project 2
Client-side: Flex application (runs through web browser)
Server-side: PHP (custom built PHP framework) & MySql
Client-server communication: AMFPHP/Remote Object, Flash Media Server

As you can see, this kind of layering is inherent to any RIA application by nature, but our focus is splitting the client-side logic further into an additional set of layers. It is important to note that this is generally what you want to be considering before starting any development work on the project. Of course, that’s easier said than done, which is why a large number of applications in any language are overhauled once or even twice a year because there just wasn’t enough scalability built into the previous version. Nonetheless, using this article as a resource when you first begin the design of a what could become a fairly large application will definitely put you a step ahead. The same also applies to smaller applications that require a lot of custom functionality (i.e. using the built-in flex components are not really an option).

Layer 1: The Business Layer

The business layer is the core of the client side application and is completely encapsulated in such a way that nothing is ever brough up to the user interface level. In other words, it is completely hidden and works entirely behind the scenes. It’s job is to feverishly work to make sure that the user interface always has the data that it needs, when it needs it. The business layer should include: the data model, a set of value object classes, an event model, its own internal services layer for communication with the client side database (if applicable) and the server, and a primary controller class for the user interface to hook into. We make this layer its own flex library project because it has no dependency on display whatsoever.

Layer 2: Custom Component and Behavior Layer

This is the “middleman” of our user interface, and is often composed of classes built with the factory design pattern. Its job is to listen for events fired from the business layer and instantiate it’s built-in event handlers, which may be to display a popup component, change the application state, or shout out commands to particular components like “do this animation!”, or “move to here and show this data!”…you get the idea. Things you might see in the component and behavior are: custom actionscript components, use of the drawing api, programmatic animation and movement, programmatic skinning, and factory classes that ultimately control all of the behavior of the display components. We create a separate Flex library project for this layer as it is not directly part of the display. Note that we can even place some of our mxml components in this layer and still keep it as a separate library because we can just call those components from the display layer if we wanted to. Whether or not you do this however, largely depends on the size of the application. Otherwise, I suggest keeping all of the mxml in the display layer.

Layer 3: The Display Layer

This is what we can refer to as “the UI layer”, in that it defines our user interface. This is typically where you will find most, if not all of the mxml files. This is our Flex or Air application project, and it includes the business layer and component/behavior layer libraries by referencing them accordingly (see below, under “Setting it Up”). Very little actionscript should be needed in these mxml files, as they are like “dummy” files that simply define the layouts of the different states of our application. They are more like “wireframes” than anything, as our actual design should be defined either in CSS stylesheets or on layer 2 for programmatic skins. My suggestion is also to do some research on the flex component plugins for Illustrator, Flash, Photoshop, and Fireworks if you haven’t already. Using these nifty little tools that Adobe created for us, we can let the design application compile a single swf for us after you’re done creating your skin, with all of the images inside of that single swf file, then import it into Flex Builder by going to File->import->skin artwork and selecting the skins you want to import. This will save you a considerable amount of time, and allows you to take the abstraction of your application one step further by separating the design from the layout on the display layer.

Setting it Up

When you setup the layer 1 and 2 projects, when you go to File – new flex project, make sure that “flex library project” is selected in the configuration window that pops up. When you setup the Display Layer project (I would suggest choosing a different name than “Display Layer” by the way, but that’s up to you), make sure that Flex Application is selected. Then go to the project properties for the Display Layer project in flex builder, click “Flex Library Build Path”, select the Library Path tab, and click “Add Project” (as opposed to add swc) and add the layer one and two libraries that way. I suggest adding swc’s or adding a swc folder (which you then place your swc libraries into, usually called “lib”) only for components or libraries that are complete in their entirety and you will not be making changes to. The “Crypto” or “Corelib” swc libraries offered by adobe for data serialization and data encryption are examples of when you would add a swc or swc library folder (and place your swcs inside of it, which is the best way to go). That is not to say that you can’t use the swc’s for your libraries, as whenever the swc is recompiled, it will automatically be updated in the main application project, but Flex still has some bugs with regard to this functionality, so my recommendation would be to steer clear of it for now unless the library does not need to be modified.

Final Thoughts

It is worth noting that this structural pattern caters very nicely to multiple-developer environments, and each layer could even be split further into additional libraries, where each developer has their own library project, and because so little development is really happening on the display layer (it should only account for maybe 5 to 10% of the application at most), developers rarely run into each other because they are mostly working on their own library project. Each developer can additionally test their code by running the main application mxml file in the Display Layer application locally, which has all of the libraries referenced. Source control is obviously critical for this to work though.

Hopefully this article sparked some new ideas, and feel free to leave a comment describing how you might alter this structure with your own ideas and design patterns.

Happy Flexing!

Possibly Related Posts:



Posted by Dan Orlando on September 29th, 2008 :: Filed under Enterprise Flex, Tutorials
Tags :: , , , , , , ,