Archive for September, 2008

Flex in RIA Development

The session detailed about Flex in RIA Development. The PPT contents of the session is available here.

Using IViewCursor for XML Traversing

The source code for using IViewCursor for XMLListCollection Navigation is here.

Flex 3 Vs Gumbo

This link describes the most differences of Flex3 and Gumbo

Welcome the user with his name

Guessing the end-user name, for AIR Applications.
šŸ˜‰
var nameStr:String = File.userDirectory.name;

Eval mathematical Expression using AS3

The below code is example for how to use MathParser.asĀ used for evaluating maths expressions using flex. Inspired from flashmaths

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; backgroundColor=”#333333″ creationComplete=”calculate()”>
<mx:Script>
<![CDATA[
[Bindable]
private var evalStr:String;
private var mpExp:MathParser = new MathParser([ ]);
private function calculate ():void {
var compobjVal:Object = mpExp.doCompile(mathStr.text);
evalStr = String(mpExp.doEval(compobjVal.PolishArray, []));
}
]]>
</mx:Script>
<mx:TextInput id=”mathStr” text=”((7*(1-8))*9)-6+7″ change=”calculate()” />
<mx:Text id=”resVal” color=”White” text=”{evalStr}” />
</mx:Application>

Using garbage collection

The below component can be used for monitoring/debugging the memory usage in your application. This also portrays about how to force the garbage collection or emptying the memory usage.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; layout=”horizontal” >
<mx:Script>
<![CDATA[
import flash.events.TimerEvent;
[Bindable]
private var minmem:Number = 0;
[Bindable]
private var totalmem:Number = 0;
[Bindable]
private var maxmem:Number = 0;
private var timer:Timer;
private function doGarbageCollection() : void
{
var lc1:LocalConnection = new LocalConnection();
var lc2:LocalConnection = new LocalConnection();
try
{
lc1.connect(“empty”);
lc2.connect(“empty”);
}
catch (e:Error) {}
}
public function start() : void
{
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, timerHandler, false, 0, true);
timer.start();
}
public function stop() : void
{
totalmem = 0;
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
timer = null;
}
private function timerHandler(e:TimerEvent) : void
{
totalmem = System.totalMemory;
maxmem = Math.max(maxmem, totalmem);
if (minmem == 0)
{
minmem = totalmem;
}
else
{
minmem = Math.min(minmem, totalmem);
}
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem label=”Minimum : “>
<mx:TextInput id=”minimum” editable=”false” text=”{minmem}” />
</mx:FormItem>
<mx:FormItem label=”Current : “>
<mx:TextInput id=”current” editable=”false” text=”{totalmem}”/>
</mx:FormItem>
<mx:FormItem label=”Maximum : “>
<mx:TextInput id=”maximum” editable=”false” text=”{maxmem}”/>
</mx:FormItem>
<mx:HBox>
<mx:Button label=”Monitor” id=”monitors” toggle=”true” click=”{monitors.selected ? start() : stop() }”/>
<mx:Button label=”Clear” click=”doGarbageCollection()”/>
</mx:HBox>
</mx:Form>
</mx:Application>

Debug Flash Player Capabilities

The below code debugs the capabilities of system, might be useful for debugging.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; layout=”horizontal”
initialize=”init()”>
<mx:Script>
<![CDATA[
import flash.system.Capabilities;
import mx.utils.ObjectUtil;
private function init() : void
{
var _capObj:Array = new Array();
capability.dataProvider = objectToArray(Capabilities);
}
private function objectToArray(cap:Class) : Array
{
var capObj:Object = ObjectUtil.getClassInfo(cap);
var _capArr:Array = new Array();
for each (var _capPropObj:Object in capObj.properties)
{
if (_capPropObj.localName != “prototype”)
{
var capProp:Object = new Object();
capProp.Capability = _capPropObj.localName;
capProp.Value =Capabilities[capProp.Capability]
_capArr.push(capProp);
}
}
return _capArr;
}
]]>
</mx:Script>
<mx:DataGrid id=”capability” width=”100%” height=”100%” />
</mx:Application>