Sunday, June 20, 2010

Never apply CSS while to textarea using styleSheet property

var myCSS:StyleSheet = new StyleSheet();
TextArea.styleSheet=myCSS;


Instead of attach to TextArea add CSS related code to HTML code.

i.e.

TextArea.htmlText("html tag with css class just like your normal HTML")

will work in all type of browser and scenario where you are fetching RSS feed into TextArea (which will get reloaded every time you have new feed)


Enjoy.

Sunday, May 30, 2010

FocusManager getIndexOfNextObject in Flex Application

mx.managers::FocusManager/getIndexOfNextObject

Error means FocusManager is looking for mxml component to set focus, when hit tab from flash object and fun part you don't have any mxml component to set focus.

Here is the trick create mx.button component and setStyle to null. It will invisible and focus manager can find the component to focus. Now application won't crash or hung.

myButton.setStyle('skin', null);

(mx:Button skin='{null}' )

.myButtonStyle {
skin: ClassReference(null);
}

(mx:Button id="myButton" styleName='myButtonStyle')

Enjoy.

Friday, May 21, 2010

Dynamically resize nested Flex List with variableRowHeight

I was stuck recently with a Flex component that had a List with an itemRenderer. The itemRenderer contained another List with an itemRenderer. Now the problem with this is that the data had unique counts and the lists had variable row heights (variableRowHeight = true). The result was that containers would not dynamically resize enough to display the whole List. In other words, the List was clipped and vertical scroll bars were displayed.

Sounds familiar to me when I had same problem as above developing comment component. I found solution in following blog

1. Link to the reference blog


2. You can also visit another blog post with good example for same problem

Bryan Bartow


Hope that helps.

Sunday, May 2, 2010

Dynamically change height of TileList

You have to adjust rowCount of Tile List to make height according to data at runtime. In below example if column count is 1 you rowCount="data.length()". Now data can be XML children.length() or array.length or any data length.

[mx:TileList id="_videoList" rowCount="{data.length()}" updateComplete="changeHeight"]

You can also updateComplete if you have column count more than 1.

private function chanegHeight():void{
var rc:int = Math.ceil(data.length() / _videoList.columnCount);
if (_videoList.rowCount!=rc) _videoList.rowCount = rc;
}

Cheers,
Nehul

Thursday, April 29, 2010

Auto justify text use mx:Text

If you want auto justify for text in

[mx:Label truncateToFit="true" text="xyzx"]

use [mx:Text]

line break in text="hello\nworld"

Monday, March 29, 2010

XML error while connecting Flex 4 to Java using BlazeDS 4 in Flash Builder

You might face of the following error while creating data service using BlazeDS.

=========================
ERROR: XML parse error: Error on line 1 of document: cvc-elt.1: Can not find the declaration of element ‘model’. Nested exception: Can not find the declaration of element ‘model’.
=========================

In that case make sure you download latest BlazeDS 4 nightly build. Once you unzip the file you will get war file. Just dump that with different name under Tomcat/weapps directory. You have to copy files from lib directory into existing application webapps//WEB-INF/lib directory.

Building Flex 4 application for BlazeDS 4 Remoting destinations using Flash Builder 4

Everybody knows Flex 4 has great features like connecting to different backend using BlazeDS or PHP, ColdFusion, LCDS or HTTPService/Web Service.

Now you can create Flex 4 UI without doing single line of code. First you have to get the following software

1. Flash Builder 4
2. BlazeDS 4 or nightly build is fine
3. MySQL server
4. Create schema and table.
5. Create Java Class to get data from MySQL. Also create public method with return type as List(Object) so you can bind them to Flex DataGrid easily.
6. JDK 1.6 installed.
7. Tomcat 6 installed.

Please note you will have more complex things to do in real life so just take above as exercise.

1. Create Flex Project in Flash Builder and select J2EE as backend and select BlazeDS.

2. Setting BlazeDS 4.
After you copy your blazeDS.war into tomcat/webapps directory go to webapps//web.xml and make changes to RDSServlet part as following

{param-value}false{/param-value}

3. You have to set your destination in tomcat/webapps//flex/remote-config.xml

Please make sure you have Java class name in tomcat/webapps//WEB-INF/classes directory.

4. Select "Data" --> "BlazeDS" from Menu option of Flash Builder. In new window it will show you destination name i.e. {servicename} from step 3. Click on checkbox next to it and click on "Finish" button.


5. After that drag DataGrid component in Flex Project using Component view. Still in Component view right click on DataGrid and select "Binding Data" option. It will prompt you to select service and method name. If you have more than one method select one you want more combobox.

After that everything is done by Flash Builder.

RUN You application to see data populated in datagrid without single line of coding in Flex 4.

You can also create free form i.e. (mx:Form) for the same method call on destination. If you have method call findAll() for users or anything else it will create form with option to hand pick required field for edit, update or delete operation.


Enjoy,
Nehul