Thursday, August 30, 2007

Flex: Checkboxes,repeaters,

Recently I've discovered this GREAT tool called Flex from Adobe, which solved one of my great problems: I can do a little bit of scripting but i am NO designer, so usually my GUIs end up giving a very bad impression of the overall app. Flex is here to save the day. Flex allows anyone to create streamlined, compatible GUIs in no time. But there is so much more to Flex than just GUIs. It uses both MXML and ActionScript so you have easy MXML interface creation along with a full Object Oriented language.

It is INCREDIBLE how all of us have being spoiled into stateful programming, I have had the hardest time trying to think stateless. So i have take baby steps.

This next Flex program is very simple, but it exemplifies some of Flex's main features.

So here it is:


xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="creationCompleteHandler();"
>


private function creationCompleteHandler():void
{
userRequest.send();
}
]]>


[Bindable]
var jailh:Array =new Array;
]]>


public function addToarray(Mymine:String):void{
var match:String = Mymine;
var isChecked:int = 0 ;
for (var i:int = 0; i < jailh.length; i++)
{
if (jailh[i] == match) {
dwindow.text="";
if (jailh.length == 1)
{
dwindow.text +="\n Will shift array"+ '\n'
jailh.shift();}
else
{
dwindow.text +="\n splice:\t"+i+','+(i+1)+'\n'
jailh.splice(i,i+1);
}
isChecked=1;

dwindow.text +="Deleted"+ '\n'
dwindow.text +="Current Length! " +String(jailh.length)+ '\n' ;
myarray.text=jailh.join("\n");
break;
}
}
if (isChecked==0){
jailh.push(Mymine);
dwindow.text="Current Length " +String(jailh.length);
myarray.text=jailh.join("\n");
}
}

]]>





































Basically this is a series of checkboxes that are pulled from an XML using an HTTPService call, then when checked they are added to an array... if the are checked again they are looked up for a match in the array, if there is a match the values are deleted.

Hopefully this will help someone, I know that if I had found such an example It would have saved me hours!


Thanks!

Alejandro