27 September 2010

Flex Enterprise Development

In building Rich Internet Applications for enterprise you will need much more than online tutorials and documentation. There isn't many books about the subject, because entire field is still young but very promising. Industry needs are high right now and there's huge void where good developers should exist.

In order to bridge this gap, experienced Adobe Certified Flex Instructors Yakov Fain and Victor Rasputnis together with another Farata Systems developer Anatole Tartakovsky have published "Enterprise Development with Flex", one of the first (if not THE first) book to guide new developers into this cutting-edge field with best practices and techniques tips.

This 680+ pages book is must-have item for one more reason, it is included in Adobe Developer Library and recommended by Adobe Flex team members.

*_*

19 September 2010

Align Buttons in Flex Spark layout container

Let's say Buttons inside same group in your Flex app have different text (which is almost always the case). Code may look something like this:

<?xml version="1.0" encoding="utf-8"?>
<s:Application

xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">

<s:Group top="10" left="10">
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:Button label="first button" />
<s:Button label="second button" />
<s:Button label="third button" />
<s:Button label="forth button" />
</s:Group>
</s:Application>


Now, your Buttons have different sizes and you want all of them to have same size. You can set sizes of all Button to size of Button with highest width value using horizontalAlign="justify" property/value.

align buttons in flex spark

<?xml version="1.0" encoding="utf-8"?>
<s:Application

xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">

<s:Group top="10" left="10">
<s:layout>
<s:VerticalLayout horizontalAlign="justify" />
</s:layout>

<s:Button label="first button" />
<s:Button label="second button" />
<s:Button label="third button" />
<s:Button label="forth button" />
</s:Group>
</s:Application>

17 September 2010

One memory cell AS3 bot

It's all about instructions, not memory. Even one memory cell bot can have interesting life if instructions are written properly. To demonstrate this we'll start with most simple bot out there - the crazy bot.

The crazy bot doesn't have any memory. Every frame (or any other given time interval) crazy bot randomly choses its next destination. Create new Movie Clip with linkage name 'bot' and type next code on Timeline first frame (stage size is standard 550x400):

var _bot:bot = new bot();
addChild(_bot);
_bot.x = 275;
_bot.y = 200;

var dx;
var dy;

addEventListener(Event.ENTER_FRAME, onframe);
function onframe(evt:Event):void
{
mover(_bot);
}

function mover(a:bot):void
{
dx = Math.random()*10-5;
dy = Math.random()*10-5;

a.x += dx;
a.y += dy;
}


Now, this is one crazy bot! First 4 lines we put our bot in center of the Stage. Next we define dx and dy variables to store frame-by-frame movement. We define event listener to move our bot every frame. We do this in mover function, where every frame we get randomly chosen values between -5 and 5. This is how much our bot will move in pixels in two directions, on x and on y axis.

Now, I'll add only one memory cell to our bot. This cell will store first randomly chosen value for x axis direction. Let's see entire code first:

var _bot:bot = new bot();
addChild(_bot);
_bot.x = 275;
_bot.y = 200;

var info:Object = new Object();
info.startX = _bot.x;
info.startY = _bot.y;
info.memory = new Array();
var dx;
var dy;

function mover(a:bot):void
{
if (info.memory.length > 0)
{
if (info.memory[0] > 0)
{
dy = Math.random()*20-10;
dx = Math.random()*10;
} else {
dy = Math.random()*20-10;
dx = Math.random()*(-10);
}
} else {
dy = Math.random()*10-5;
dx = Math.random()*10-5;
}

info.memory[0] = dx;
a.x += dx;
a.y += dy;
info.startX = a.x;
info.startY = a.y;

if( (a.x > 550)||(a.x < 0)||(a.y > 400)||(a.y < 0) )
{
a.x = 275;
a.y = 200;
info.memory[0] = -1 * info.memory[0];
}

// var _dot:dot = new dot();
// _dot.x = a.x;
// _dot.y = a.y;
// _dot.scaleX = _dot.scaleY = 1+Math.random()*3;
// _dot.alpha = Math.random()*0.5;
// addChild(_dot);
}


addEventListener(Event.ENTER_FRAME, onframe);
function onframe(evt:Event):void
{
mover(_bot);
}


First 4 lines are the same. Next we have info object to store 3 things, starting position of our bot and memory Array. Even though our memory is an Array we will use only first array element, thus our memory has only one cell.

So, inside mover we have 2 if conditional loops, where second one only returns our bot to center of the Stage if it goes out of boundaries. First if loop are instructions. First we check if bot has already moved. If it isn't then memory length is zero and we go to else branch where we choose first move.

Now, if memory cell of our bot does have some value and if that value is positive that means our bot has moved to the right in last frame. We want our bot to continue to move in same direction until it reaches Stage border. That's why we give dx only positive value. On the other hand if our memory cell have negative value, we set dx to some new negative value, so our bot can continue until it reaches left Stage border.

In other words we tell our bot to keep moving in one direction until border, then to return to center and continue in opposite direction and so on ... All this with only 1 memory cell. You can modify dy value if you want him to go more up or down.

Finally, dot MovieClip is random graphic to track bot movement and make interesting drawings. Here are some examples I've made.








Now, this is created using only one memory cell. Think of what you can do by using 10 of them or 100?

*_*

15 September 2010

Next Flash Builder "Burrito" feature [video]

'Generate from usage' feature should be part of next Flash Builder release, code name "Burrito". Watch video demonstration.



*_*

11 September 2010

Flex 4.5 SDK Hero Introduction

While Flex 4.1 build is still very hot potato (released June 30 2010), new version of Flex SDK is already here, version 4.5 code name Hero. Although final Hero release is scheduled for 2011 many interesting new features already are catching attention.

New Spark controls and containers are available and ready to use Spark Form, Spark Image, Spark Formattars, Spark DataGrid. With this Flex release Adobe has abandoned Slider, separate mobile development framework because Hero will get new mobile development capabilities.

Read more about Flex Hero features.

*_*

06 September 2010

AS3 Terminal - open source project

Nice little open source project AS3Term released by Piotr Walczyszyn. You don't need to open your Flash IDE every time you want to check small chunk of code or try something quick - use AS3Term instead.



*_*

 

template by blogger templates