Tour de Flex

February 4, 2009 at 11:35 am (Flex) ()

Tour de Flex is awesome!

Permalink Leave a Comment

Validating real/integer numbers in Flex

December 19, 2008 at 4:05 pm (Flex) (, , , )

Written for: Flex

Below is a short code to determine whether a number is real (floating). To find if a number is an integer, change the domain property in NumberValidator tag from “real” to “int”.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
        ]]>
    </mx:Script>

    <mx:TextInput id="myTxtInput"/> 

    <mx:NumberValidator id="myNumberValidator"
        domain="real"
        source="{myTxtInput}"
        property="text"
        trigger="{myTxtInput}"
        triggerEvent="focusOut"
        valid="Alert.show('real number')"
        invalid="Alert.show('hmmm....unreal number?')"/>

</mx:Application>

Permalink Leave a Comment

Dynamically add element / attribute to a XML using E4X

September 25, 2008 at 12:01 pm (Flex, XML) (, , )

Written for: Flex, ActionScript 3.0

To dynamically add element / attribute to a XML; assume that it already exists in the XML and using the .(dot) operator, pass a value to it.

Here’s an example. Consider the following XML:

var albumXML:XML =
<tracks>
	    <song tracknumber="1">
	        <title>Orgasm Addict</title>
	        <artist>Buzzcocks</artist>
	    </song>
	    <song tracknumber="2">
	        <title>What Do I Get?</title>
	        <artist>Buzzcocks</artist>
	    </song>
	    <song tracknumber="3">
	        <title>I Dont Mind</title>
	        <artist>Buzzcocks</artist>
	    </song>
	    <song tracknumber="4">
	        <title>Love You More</title>
	        <artist>Buzzcocks</artist>
	    </song>
	</tracks>;

To add an additional element of <genre> to the first <song> node, I’ll use the following line of code.

albumXML.song[0].genre = 'Punk';

Similarly to add an attribute of duration to the first <song> node, I’ll use.

albumXML.song[0].@duration = '2:00';
Now if you trace the XML file, it’ll show as:
trace(albumXML);
/*
<tracks>
  <song tracknumber="1" duration="2:00">
    <title>Orgasm Addict</title>
    <artist>Buzzcocks</artist>
    <genre>Punk</genre>
  </song>
  <song tracknumber="2">
    <title>What Do I Get?</title>
    <artist>Buzzcocks</artist>
  </song>
  <song tracknumber="3">
    <title>I Dont Mind</title>
    <artist>Buzzcocks</artist>
  </song>
  <song tracknumber="4">
    <title>Love You More</title>
    <artist>Buzzcocks</artist>
  </song>
</tracks>
*/

Additionally, you can use the following methods of a XML object.

  • appendChild()
  • prependChild()
  • insertChildAfter()
  • insertChildBefore()

Permalink 3 Comments

Video: Integration of Flex with Flash CS3

September 11, 2008 at 12:43 pm (Flex, Videos) (, , , , )

Found a video by Glenn Ruehle demonstrating integration of Flex with Flash CS3. 

Video Link

Permalink Leave a Comment

FlexBuilder: Can’t find NPSWF32.dll for Mozilla FireFox

September 1, 2008 at 2:17 pm (Firefox, Flex) (, , , )

Once in a while, while debugging a Flex application, I have been show this error by Flex Builder.

C:\Program Files\Mozilla Firefox\plugins\NPSWF32.dll

Flex Builder cannot locate the required debugger version of Flash Player. You might need to install the debugger version of Flash Player 9 or reinstall Flex Builder.

Do you want to try to debug with the current version?

This essentially means Mozilla Firefox (if you have set FireFox as the default browser for loading applications from Flex Builder) can’t find the debug version of Flash player. I still haven’t found out the exact reason why it occurs. But, I have found solutions over time which tackle it. (I have always tried each solution, one after another, as sometimes one solution works in one case while the others don’t.)

Permalink 1 Comment

Difference between Display Object and Display Object Container

August 28, 2008 at 12:07 pm (ActionScript, Flex) (, , , , )

In ActionScript 3.0, anything that appears on the application screen are types of display objects and display object containers are special types of display objects. Though both are visually represented in the application in the same way, the difference between them is that one can add child display objects to a display object container. That means, you can use a Sprite as a display object container and can add shapes, bitmaps, texts,… as child display objects.

Permalink 1 Comment

How to split a pipe(|), comma(,), tab, space,… separated string in ActionScript 3.0

August 21, 2008 at 12:51 pm (ActionScript, Flex) (, , )

To split a pipe(|), comma(,), tab, space,…. separated string into multiple string values in ActionScript 3.0, you will have to use the split() method of String class. Below is short example where in a pipe(|) seperated string is broken up into multiple values and pushed into an array.

var cities:String = "Bombay|Los Angeles|Moscow|London|Rio de Janeiro|Sydney";
var citiesArray:Array = cities.split("|");

trace(citiesArray); //Result: Bombay,Los Angeles,Moscow,London,Rio de Janeiro,Sydney

Permalink Leave a Comment

Article: Introducing E4X

August 10, 2008 at 9:21 pm (Flex, XML) (, , , )

Found a great article on E4X by Kurt Cagle. Below is the link.

Introducing E4X

Permalink 1 Comment

Accessing data from a List item on mouse over

July 30, 2008 at 5:37 pm (Flex) (, )

Below is a short example in Flex on how to access data from a list item on mouse over. I’m using the rowIndex property of itemRollOver event to access the index at which the mouse is currently positioned.

<?xml version=”1.0″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>

	<mx:Script>
		<![CDATA[
		    import mx.events.ListEvent;

		    var oceans:Array = ["Pacific", "Atlantic", "Indian", "Artic", "Southern"];

		    public function displayItem(event:ListEvent):void {
		    displayTxt.text = displayList.dataProvider[event.rowIndex];
		    }
		]]>
	</mx:Script>

	<mx:List id="displayList"
		dataProvider="{oceans}"
		itemRollOver="displayItem(event)" />

	<mx:TextArea id="displayTxt"/>

</mx:Application>

Permalink 1 Comment

Commenting code in Flex Builder

July 25, 2008 at 12:39 pm (Flex) (, )

Flex Builder provides useful keyboboard shortcuts to comment code. Below are the different ways you can do it.

ActionScript(AS) Code: To toggle

  • Single Line Comment (// Lorem Ipsum)

Select single / multiple lines of code and hit Control+/ (Windows) or Command+/ (Mac OS).

  • Multiple Lines Comment (/* Lorem Ipsum */)

Select single / multiple lines of code and hit Control+Shift+C (Windows) or Command+Shift+C (Mac OS).

MXML Code: To add

  • XML Comment (<!– Lorem Ipsum –> )

Select single / multiple lines of code and hit Control+Shift+C (Windows) or Command+Shift+C (Mac OS).

  • CDATA Block (<![CDATA[
    Lorem Ipsum
    ]]>
    )

Select single / multiple lines of code and hit Control+Shift+D (Windows) or Command+Shift+D (Mac OS).

Permalink Leave a Comment

Next page »