Tuesday, January 17, 2012

Flex 3 sdk command line development with example on Linux � simple blog

Flex 3 sdk command line development with example on Linux � simple blog

Flex 3 sdk command line development with example on Linux

This post shows how to do Flex 3 development using command line compiler mxmlc under Linux
The example uses a basic actionscript 3 class and an mxml file using the class defined in the .as file.

Step 1:
Download and extract flex 3 sdk to /opt/flex_sdk_3

Hence my flex_sdk_home is /opt/flex_sdk_3

Add /opt/flex_sdk_3/bin to environment path variable.

Create project folder in workspace /home/asantoso/workspace/flex/

With project name example: actionscript

The final directory structure is:
/home/asantoso/workspace/flex/actionscript/
/home/asantoso/workspace/flex/actionscript/src/
/home/asantoso/workspace/flex/actionscript/bin/

Step 2:
Copy flex-config.xml from ${flex_sdk_home}/frameworks to /home/asantoso/workspace/flex/actionscript/flex-config.xml

cp $flex_sdk_home/frameworks/flex-config.xml /home/asantoso/workspace/flex/actionscript/flex-config.xml

Edit flex-config.xml:
vi $flex_sdk_home/frameworks/flex-config.xml

Important step:

${flexlib} is a special config file variable used by the compiler and the value refers to the directory of the sdk. in this example ${flexlib} points to /opt/flex_sdk_3/frameworks. Since you are using flex-config.xml in a different folder, you need to correct the values of external library path elements, library path elements, namespace manifest path. You can statically set the paths manually, or append ${flexlib} to external library path elements, library path elements, namespace manifest path.

Now, uncomment the source-path element, and add a path-element child in the source-path element, which points to the root src folder of our project.
/home/asantoso/workspace/flex/actionscript/src/

save flex-config.xml


Step 3:
Create actionscript file: /home/asantoso/workspace/flex/actionscript/src/com/example/quickstart/Greeter.as

package com.example.quickstart
{
public class Greeter
{
public var name:String;
private var secretValue:Number;

public function Greeter(initialName:String=”Agus”)
{
name = initialName;
}

public function sayHello():String
{
var result:String;
if(name!=null && name.length>0){
result = “Hello there, “+name+”.”;
}
else{
result=”Hello there, anonymous.”;
}
return result;
}
}
}


Create mxml file: /home/asantoso/workspace/flex/actionscript/com/example/quickstart/Greeter_mx.mxml