« April 2008 | Main | June 2008 »

May 2008 Archives

May 12, 2008

Improve the ObjectHandles library with a smoother resizing movement

A very common UI element found in many applications are those little square handles around an on-screen object that allow you to move & resize it. To do this you can use the great ObjectHandles library.

ObjectHandles (http://osflash.org/projects/objecthandles) is a library to allow a user to move and resize UI elements in a Flex based application.
It provides drag handles around controls that users can manipulate with their mouse. Any Flex component can be placed within an ObjectHandles container to quickly allow you to add functionality.

It behaves as a container object where you can put any other flex components and use its resizeable functionalities.

Features of the ObjectHandles library:

* Move & Resize Functionality for any flex component
* Ability to limit movement and/or resizing in both vertical and horizontal directions
* Ability to limit movement and/or resizing along an anchor
* Simple 1-file (.swc) install
* Mouse cursors change when over different handles
* Graphical handle support
* Aspect ratio support
* Initial rotatation support has been added

ObjectHandles is a very cool library for your project when you want to implement moving & resizing any kind of flex object.

Example usage:

In the example below you'll see two buttons in a vbox that can be moved together. This is the mxml to achieve that:

<oh:ObjectHandles x="10" y="158" width="107" height="108"
minHeight="30" minWidth="30">
<mx:VBox borderStyle="none" top="0" left="0" right="0" bottom="0">
<mx:Button width="100%" height="50%" />
<mx:Button width="100%" height="50%" />
</mx:VBox>
</oh:ObjectHandles>

Or if you want an Actionscript example:

Here's an example to dynamically load an image into an ObjectHandle and allow resize movements:

protected function init() : void
{
var oh:ObjectHandles = new ObjectHandles();
oh.height = 50;
oh.width = 50;

var image:Image = new Image();
image.source = "snowflake.png";
image.percentHeight = 100;
image.percentWidth = 100;
image.maintainAspectRatio = false;

oh.addChild(image);
oh.allowRotate = false;

genericExamples.addChild(oh); // replace genericExamples with a canvas in your application
}

Improving the experience of the ObjectHandles library

When you drag or resize an object from right to left or from up to down everything works great.

But if you to resize the object back (from right to left) you'll see that the inside object will cause a strange flickering.

To prevent this we can use the "Flex Move Effect" and "Flex Resize Effect" instide of change programmaticaly width and height and x and y.

How it actually works:

Inside the ObjectHandles.as Actionscript 3 class, you can find the protected function onMouseMove(event:MouseEvent) : void.
This is the function that moves and resizes UI elements in a Flex based application. Find the following line inside the ObjectHandles.as:

if( wasMoved || wasResized )
{
applyConstraints(desiredPos,desiredSize);
x = desiredPos.x;
y = desiredPos.y
width = desiredSize.x;
height = desiredSize.y;
}

The applyConstraints() method simply applies restrictions to your objects like xAnchor, minium size, etc. The other four lines simply set the x,y coordinates and the width and height properties of the Flex object.

Now let's change this four lines to prevent the strange flicker bug that affects the object :

if( wasMoved || wasResized )
{
applyConstraints(desiredPos,desiredSize);

if(moveEffect.isPlaying){
moveEffect.end();
}
moveEffect = new Move();
moveEffect.target = this;
moveEffect.duration = 1;
moveEffect.xTo = desiredPos.x;
moveEffect.yTo = desiredPos.y;
moveEffect.play();

if(resizeEffect.isPlaying){
resizeEffect.end();
}
resizeEffect = new Resize();
resizeEffect.target = this;
resizeEffect.duration = 1;
resizeEffect.heightTo = desiredSize.y;
resizeEffect.widthTo = desiredSize.x;
resizeEffect.play();
}

It replaces the brutal property changing of the widget with a smoothness move and resize effect provided by Flex.

In the next post we will see how to create a snap to grid and a snap to line effect.

Conclusion and references:


ObjectHandles google code home
Class Move
Class Resize

May 15, 2008

Flex rich interface design: why big companies choose Flex

It is interesting to see how big companies choose Flex to interact with costumer on their websites. We are used to see lots of nice widgets created with this kind of technologies but maybe a little bit less used to find useful and funny applications in the Net. Let’s give some example!

flex_Hd1.gif

On Harley Davidson website there is a really nice application where you can customize a bike with all the accessories and even get an estimation of the price and of a monthly payment solution. The interface is really easy to use, it has a clean design with few icon, some boxes to show images and contents, they have used some of the classical Flex elements as accordion and tab menu.

flex_Hd3.gif

You can see accessories in details and add them on the bike in order to see in real time how it will be the final result, for every pieces you can read detailed information and if you change your mind about one of them you can always take it away from the bike and start looking for something different.

flex_Hd.gif

This is a different approach to interact with costumer, you can tell that it’s not a game because of the professional interface concept, all the information are detailed and you can really buy a 14.000$ bike but at the same time you can just create your own perfect model dreaming to have it maybe one day:)

http://customizer.harley-davidson.com/GMA_customizer.jsp

---------------------------------------------------------------------------------------------------------------------------------

Flex_Hp.gif

Another nice Flex application is the HP Print Studio, it’s free and you can use it to create customized calendar, greeting cards, invitations and even business identities.
The interface is user friendly and it is easy to follow every necessary step to print you project. In this case HP designed an interface with more interaction than the HD’ s one using elements as lighting menus, pictures floating, horizontal navigation and pop-up window to show the selected item and to see some advice from the company about the right paper to use in order to print the project. The zoom system is very useful.

Flex_Hp2.gif

That’s a good example of promoting products letting people have fun with a nice tool.

http://h30393.www3.hp.com/printing/app/us/en/launch.aspx

---------------------------------------------------------------------------------------------------------------------------------

Speaking about widgets there is a nice one created by AOL that shows music videos using main categories as pop, country, latin, hip hop, most watched etc.

aol.jpg

It has a plain interface but very effective and easy to use, it gives you information about the artist and the song and the chance to create your list of favorites and share it with friends sending an email directly inside the application or even copy the code to post it on a website. It has some nice features to customize videos views and even the interface views as full screen mode or as side widget.

aol2.jpg

You can download it here http://music.aol.com/help/syndication/desktop-widgets

Have fun with all these applications!

May 26, 2008

Google Maps API for Flex and Flash: some tips and notes

Finally the official version of Google Maps for Flash is arrived.
Google has just released the Actionscript API that provides map functionalities to web applications in a way really similar to the Javascript version.
You can follow the instructions in the Setup or Tutorial pages on Google Code to easily build your web map application.
Here is a sample application based on data from Yubuk (click on the image):
GoogleMapsFlex

And now some hints that can be useful when creating your first Flex application with Google Maps:

1) Remember to add the .swc library provided by Google in their SDK in your compiler options. If you are using Flex Builder you can do that simply going in the project properties, under Flex Build Path, then Library Path and click Add SWC. Otherwise, if you like to use the command line, you can use the -library-path command as explained in the Google tutorial.

2) Pay attention to the events: you can't use the standard Flex events but you need that ones provided by the Google SDK, such as MapMouseEvent.CLICK.

3) Custom markers have a bug in the version 1.3. To avoid this bug there's a workaround in Google Code. The example has a small error in the marker event listener, the event should be MapMouseEvent.CLICK (as explained above).

I think that Google made a great work porting their Google Maps API to Flash. It is still incomplete but it's already possible to see the huge potential provided by the cooperation between Google Maps and Flex. I'm sure that in the near future there will be many interesting RIA based on these technologies.

About May 2008

This page contains all entries posted to Comtaste Consulting | Enterprise RIA consulting and development in May 2008. They are listed from oldest to newest.

April 2008 is the previous archive.

June 2008 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33