Category Archives: Flex 4

Flex 4.x loop on spark Form

4
Filed under Flex, Flex 4, Open Source Stuffs

I miss this part on Flex 4.x, since in Flex 3.x you easily loop throw Form Items and their fields, which was in compensation of getChildren().

Since we have in Flex 4.x a Skin architecture diffs from Flex 3 , we no longer have getChildren(), and just leave us an option numElements.

Hard for may developers out there and makes you opt-in for statis solution, on naming it all form itens and clear them all in a function. Don’t be shame if you already did that, it’s normal when you don’t know deep in on Flex SDK.

All right, I want to share with you guys, a little Manager Class, which I called, FormManager to workaround on that situation, and get rid of that.

////////////////////////////////////////////////////////////////////////////////
//
//  RIACYCLE INC. LTDA BRAZIL
//  Copyright 2011 RIACycle Inc. LTDA
//  All Rights Reserved.
//
//  NOTICE: RIACycle Inc. permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//	Code Licensed by MPL http://www.opensource.org/licenses/MPL-1.1
//
// Author: Igor Costa
// 
////////////////////////////////////////////////////////////////////////////////
 
 
package
{
	import mx.collections.ArrayList;
	import mx.core.IVisualElementContainer;
	import mx.core.UIComponent;
 
	import spark.components.ComboBox;
	import spark.components.Form;
	import spark.skins.spark.ComboBoxSkin;
 
	public class FormManager
	{
		public function FormManager()
		{
		}
		private static var _numelements:ArrayList;
 
 
		/**
		 * @public
		 *  Static method to clear all values filled in a given Form
		 * 
		 * Usage FormManager.clearFields(myForm);
		 * @see spark.components.Form;
		 * @see mx.core.IVisualElementContainer;
		 * */
		public static function clearFields(value:Form):void
		{
			for (var i:int = 0 ;i <= value.numElements-1;i++)
			{
				var item:IVisualElementContainer = value.getElementAt(i) as IVisualElementContainer;
 
				for (var j:int = 0; j<=item.numElements-1;j++)
				{
					var input:UIComponent = item.getElementAt(j) as UIComponent;
						if(input.hasOwnProperty('text'))
							input['text'] = '';
						if(input.hasOwnProperty('textFlow'))
							input['textFlow'] = null;
						if(input.hasOwnProperty('selectedItem'))
							input['selectedItem'] = null;
						if(input is ComboBox)
							ComboBox(input).textInput.text =''; // fix the bug on default ComboBoxSkin class
						if(input.hasOwnProperty('selectedItems'))
							input['selectedItems'] = null;
						if(input.hasOwnProperty('selectedIndex'))
							input['selectedIndex'] = -1;
						if(input.hasOwnProperty('selected'))
							input['selected']= false;
 
				}
			}
		}
		/**
		 * @public
		 *  Static method to return an ArrayList of all fields in a given Form
		 * 
		 * Usage :  var elements:ArrayList = FormManager.getElements(myForm);
		 *            for each (var item:* in elements)
		 *                 {
		 *                   trace(item);
		 *                  }
		 * @see spark.components.Form;
		 * @see mx.core.IVisualElementContainer;
		 * */
		public static function getElements(value:Form):ArrayList
		{ 
			_numelements = new ArrayList();
 
			for (var i:int = 0 ;i <= value.numElements-1;i++)
			{
				var item:IVisualElementContainer = value.getElementAt(i) as IVisualElementContainer;
 
				for (var j:int = 0; j<=item.numElements-1;j++)
				{
					var input:UIComponent = item.getElementAt(j) as UIComponent;
					_numelements.addItem(input);
				}
			}
			return _numelements;
		}
	}
}

It’s worth to migrate my Flex 3 app to Flex 4 app?

1
Filed under Flex, Flex 4, Flex Components

Got a question today on skype over a developer from US, asking me some other things and finally all explanation gave to him he asked me if it worth to migrate a current built app done in Flex 3.x SDK to Flex 4 SDK.
Besides the fact of corporate world, Homologate than start using for first class projects, it’s worth at all to start using Flex 4 SDK. And now why?

To better help you here’s a list of things that you will consider before and after choose Flex 4 SDK:

Flex 4 vs. Flex 3:
Each other does not compete with each other, they work together and smooth, guys from Flex SDK team and their manager (Deepa), did an amazing job putting this to work smooth. You can easy use both Spark components and Halo components together without hassle. Both products SDKs was built to distinct goals. When Flex 3 SDK was shipped to the market was consolidating itself to solve most problem in industry of RIA applications, the easiness of doing incredible products with desktop behavior and data-ware prospect. Which includes a hell lot of new components, new charts capabilites and until today you still uses those creations. Flex 4 SDK was built to help ensure that thinking before, help not just creating easyness UI for applications but, do them beauty.
Today worlds we don’t just have desktops to use, we have mobile devices, devices of any kind and with the current look and feel of Flex components it’s hard to keep code up to date and still working on those types of screen/hardware. Where Flex 4 SDK came to close this gap, making beauty, usefull and maintanable your work.

Composite vs. inheritance

Still today you can do both with Flex 3 SDK. the 3th version and his variants can support composite, as you know Flex 4 SDK still uses the inheritance but main goal of Flex 4 SDK is composite components, more easy and fun to code, increasing among many other things that you will see in your day-by-day job.
To illustrate the easy of creating new components in Flex, please see theses slides from Mrinal Wadhwa, his slides explanation will let you know more about what I’m talking to.

Code confort:

When you have a mature SDK that let you know what you’re doing, it’s hard to keep distance from it. Sample of that people missunderstand that an mature SDK is that SDK that it’s out of the box components, just drag and drop and it’s working. In some parts is cool programming in that way for small, prototype and presentations. But in a real world you will have to costumise each component, don’t you? In Flex 3 SDK you have to handle pretty well and know all the behavior of Flex 3 Component life cycle. Many developers are still facing on how is the better approach. I admit that it was usual hard to get working. But in Flex 4 SDK life cycle of a component get ridiculous simple. You now can have decouple UI, you can split the design and logic ui in two files. Letting you do the hard part of costumization easy to you. Never been so easy to create and deploy your own custom components without worry to meet the qualified classes or behavior methods to declare in order to properly work. This is the past, from now one you will see in your future Flex 4 SDK projects how this become easy.

Performance:
We have today a world that is slave of clock and everything that comes to you it’s for delivery yesterday, don’t happen with you? And to keep in track time and projects you need a tool, that facilitate all of these work, it’s basicly a give me what I want in the time I want. the new mxmlc compiler is twice fast than the old one in Flex 3 SDK. Part of that is to help the developer increase their producitivy and increasing that you have loved developers on your pocket. Team did a good job. In some cases for example I’ve notice that increased 4.3x times than before. It’s like I don’t need no more coffee break as sorry to producitivy.

Imaginable components:
Imaginated create that mo’ fc’ component you always wanted and don’t have the skills necessery to create? Simple, you can do design right? You have Flash Catalyst to do the dirt job to you. and it will compile to you a nicely tag component ready to be used for your developer. Their are still working on this tool to get worth using. But if you don’t want to wait, you can right now test a beta version of this tool in the Adobe Labs.

Migration Code:
One of the principal concern is motivation on gains to move code on to new workflow of Flex 4 SDK does. A worth looking is the documentation that specify straight to the point where show all new way of doing in Flex 4. It’s not hard to update your current code, you just have to adapt, a sample of that I bet you will only need 40% of your current code migrated to Flex 4 SDK standards. If you do much use of States,HBox,VBox. I increase this value to 50% of code migration.

All theses worth mention can help you understand if worth right now to migrate to Flex 4 SDK. There’s another indirect benefits of start using Flex 4 SDK, like direct access to the new API of Flash Player, AIR, code execution faster, less open bugs on the database,etc. It’s now up to you decide.

Coding Conventions for Flex 4 SDK, some points has no meaning at all

1
Filed under 3.0, ASDoc, Actionscript, Flex, Flex 4, Open Source Stuffs

Flex Team released the doc for coding conventions in the next Flex 4 SDK, but there’s some points in the document that to me has no meaning at all.

Some folks point out their opinion about the code guide. I disagree with Bit-101 about Adobe fixation on Flex word to avoid this and use as3 as one language. You’re right Keith when you say that but the document as well is only for Flex 4 SDK code guide for Actionscript classes placed on the SDK as well, not the language at all.
But some of point I mean there’s no meaning is the Array part, like you see:

Array indexing
Don’t put any spaces before or after the left bracket or before the right bracket.

Do this:

a[0]
Not this:

a[ 0 ]

Blank spaces are really necessery to worry about it? When you’re working with developers using Mac and PC, you will extra characters over the pile and this point should leave it. Who use both platform will see this in action.

And in the next section of doc they did what they adviced before in array literals

Array literals
Put a single space after the left bracket and a single space before the right bracket, and put a single space after (but none before) each comma.

Do this:

[ 1, 2, 3 ]
Not these:

[1, 2, 3]

[1,2,3]
An empty array is a special case.

Do this:

[]
Not this:

[ ]

Make some confusion here that is missing the point.

And other points are still confusing. Hope not offend anyone who wrote this. Just my view that this document need improvements.