Wednesday, June 8, 2011

What is Flex?

In this tutorial we will begin to learn Flex, with the help of the FlashDevelop IDE.

You have probably heard of Flex. It is, basically, a language used to create Flex RIAs, which, just like AS3, work on the Flash platform. In fact, Flex in some way is AS3. But its more focused on creating applications. Flex consists of mxml and AS3, that you can put into your script. Thanks to this mxml, some features that could be done with AS3 can now be done easier and faster.

For example, how would you create a text field in AS3? You would first create the TextField object, then set its properties, and in the end, if you only want some basic stuff without formatting (which would require you to create a new TextFormat object and would take more lines), you would get something like this:

var myText:TextField = new TextField();
myText.x=10;
myText.y=20;
myText.text="Hello, everybody!";
addChild(myText);

In mxml, this would only take one line:

<mx:Label x="10" y="20" id="myText" text="Hello, everybody!" />

You can see that mxml is a block-language, it is based on XML.

To import an AS3 script into the code, we need to have it in the CDATA object, like this:

<![CDATA[
// AS3 stuff here
import mx.controls.Button;

private function myFunction():void {
var myButton:Button = new Button();
myButton.label = "This button is created using AS3!";
myButton.x = 10;
myButton.y = 40;
this.addChild(myButton);
}
]]>

Perhaps, Flex is somewhat similar to Ajax. I'm not talking about the syntax here, but rather the fact that both of these languages include one scripting langauge (AS3 in Flex, Javascript in Ajax) and one xml-based language (mxml in Flex, html in Ajax).

Now that we know what Flex is, we need to get our tools ready to be able to create Flex applications.

Flex SDK is an open-source SDK, which means it is free and you can download it off the Adobe website. There's an Adobe Product called Flash Builder, which is the Adobe's tool for Flex developers, but it isn't free. I am going with a software called FlashDevelop, that is just as good (minus some features that aren't necessary) and completely free. You can create not only Flex applications in FlashDevelop though, you can do pure AS3 projects, and even HTML, PHP and other projects. So it's a pretty nice multifunctional program.

We'll get our tools ready for Flex development in the next tutorial.

Thanks for reading!

No comments:

Post a Comment