random


18
Feb 10

Is flex timer Accurate?

Would you would expect timers in ActionScript 3.0 to be accurate??

“yes, of course!” But there’s a problem:

If you set a Timer to go off indefinitely (i.e., with a repeatCount of 0), it appears that the timer doesn’t start the next interval until the listener function returns. So if you don’t correct for this, then your timer function will creep by the duration of the listener function. If your listener function does something that’s potentially lengthy, you might want to execute it with a callLater() so that the timer isn’t affected. But the timer will still creep unless you apply a correction. Here’s some sample code that demonstrates the effect, side-by-side with a correction.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
< ?xml version="1.0" encoding="utf-8"?>
<mx :Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="{onCreationComplete(event)}">
    </mx><mx :Script>
        < ![CDATA[
            import mx.utils.StringUtil;
            import mx.events.FlexEvent;
            private const BASE_INTERVAL:Number = 1000;
            private var _creepingTimer:Timer = new Timer(BASE_INTERVAL);
            private var _steadyTimer:Timer = new Timer(BASE_INTERVAL);
            private var _startTime:Date;
 
            private function onCreationComplete(e:FlexEvent) : void
            {
                _creepingTimer.addEventListener(TimerEvent.TIMER, onCreepingTimer);
                _creepingTimer.start();
                _steadyTimer.addEventListener(TimerEvent.TIMER, onSteadyTimer);
                _steadyTimer.start();
                _startTime = new Date();
            }
 
            private function onCreepingTimer(e:TimerEvent) : void
            {
                var now:Date = new Date();
                var deltaMS:int = now.time - _startTime.time;
                uiCreepingLog.text += StringUtil.substitute("\r{0}", deltaMS);
            }
 
            private function onSteadyTimer(e:TimerEvent) : void
            {
                var now:Date = new Date();
                var deltaMS:int = now.time - _startTime.time;
                uiSteadyLog.text += StringUtil.substitute("\r{0}", deltaMS);
                var offset:int = deltaMS % BASE_INTERVAL;
                _steadyTimer.delay = offset < 500 ? BASE_INTERVAL - offset : BASE_INTERVAL;
            }
 
 
        ]]>
    </mx>
    <mx :HBox width="100%" height="100%">
        <mx :TextArea id="uiCreepingLog" width="50%" height="100%" text="Creeping timer:"/>
        <mx :TextArea id="uiSteadyLog" width="50%" height="100%" text="Steady timer:"/>
    </mx>

read the orignal post at : joy of flex


18
Feb 10

Geometry 3 points in line test

inLine

GeometryMath.isLine() static function tests 3 Points and returns true if these points are in line. Optional 4th parameter defines if you require point2 to be in the middle between 1 and 3. Function is not based on vector algorithm, but on triangle equation. This simple function was developed in order to optimize number of points necessary to draw some paths. To draw a line, you do not need all the points, you can omit all the middle points that are on the same line and the result looks the same – optimizes performance or storage.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static function isLine(point1:Point, point2:Point,
point3:Point, orderSensitive:Boolean = true):Boolean
{
var x1:Number = point1.x - point2.x;
var x2:Number = point2.x - point3.x;
var y1:Number = point1.y - point2.y;
var y2:Number = point2.y - point3.y;

if(orderSensitive &amp;&amp; ((x1 &gt; 0 &amp;&amp; x2 &lt; 0) || (x1 &lt; 0 &amp;&amp; x2 &gt; 0)
|| (y1 &lt; 0 &amp;&amp; y2 &gt; 0) || (y1 &lt; 0 &amp;&amp; y2 &gt; 0)))
return false;
else if(!y2)
return !y1;
else if(!x2)
return !x1;
else
return x1 / x2 == y1 / y2;
}

17
Feb 10

Did Google copy flex charts from wordpress??

Google just did a makeover on their Google Analytics package, completely revamping their UI. We won’t get to play with it for a while, though, because they’re slowing rolling out the new version across all their myriad users. Undoubtedly this strategy has two business-centric side effects:

  1. With a slow rollout, they can fix any bugs in the application which they might have overlooked. By the time the 95% start to use it, the 5% will have made it perfect.
  2. They can make it sure it scales. As they add site after site, they can accurately measure how much of their distributed grid will have to power the new, heavier UI.

google-stats.jpg

I don’t have access to a live version, but this screenshot looks a lot the newly announced free stat tracking app from WordPress. For comparison, here’s a screenshot from their web page:

wp-stats.png

I won’t argue that they’re the same, but the style is similar–and WordPress came way first. Copying or unconscious emulation? You decide.


25
Sep 09

doing nothing!

I got the Swine flu :(

well was browsing through a few examples and saw a datagrid pagination example.

check it out  here.


10
Jul 09

Dynamically add remove columns in a datagrid

I had a hard time figuring out how to add remove columns  dynamically from a datagrid and after lots of code iterations I have reached a workable scenario. Right now the code is fairly easy to understand and can be enhanced to a gr8 deal,

I still need to add other important functionalities.

  • Close headerrenderer for each column
  • delete entire row functionality
  • user defined default state
  • and much more…

Dint get the time to complete this post but someday i will surely post a complete working APP
by that time check out the code  USE AND MODIFY AS PLEASED!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
< ?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="100%" height="100%" >
   
    <mx:hdividedbox height="100%" width="100%" dividerRelease="handleDivderRelease()">
    <mx:script>
        < ![CDATA[
            import mx.controls.CheckBox;
            import mx.controls.ComboBox;
            import mx.controls.dataGridClasses.DataGridColumn;
           
            public var counter : int = 0;
            public var conDataProvider : Array =[{label : "col1", data : "c1"},
                {label : "col2", data : "c2"},
                {label : "col3", data : "c3"},
                {label : "col4", data : "c4"},
                {label : "col5", data : "c5"},
                {label : "col6", data : "c6"}];
           
           
            private function hideShowColumns():void{
                var actualColumns:Array = ResultGrid.columns;
                var actualSelectedColumns:Array =  lstColumns.selectedItems;
                var dataGridColumn:DataGridColumn;
                var sDataField:String;
                var sDataFieldCur:String;
                var columnVisible:Boolean
                for (var i:int=0;i<actualColumns.length;i++)  {
                    columnVisible = false
                    dataGridColumn = actualColumns[i];
                    sDataField = dataGridColumn.dataField;
                    for (var j : int = 0; j < actualSelectedColumns.length; j++)  {
                        if(actualSelectedColumns[j] == null) continue;
                        sDataFieldCur = actualSelectedColumns[j].data;
                        if (sDataFieldCur == sDataField)  {
                            columnVisible = true;
                            break;
                        }
                    }      
                    if (columnVisible) {
                        dataGridColumn.visible = true;
                    }else  {
                        dataGridColumn.visible = false;
                    }
                }
            }
           
            private function selectAll():void{
                lstColumns.selectedIndices=[0,1,2,3,4,5];
                hideShowColumns();
            }
           
            private function clearAll():void{
                lstColumns.selectedIndices=[];
                hideShowColumns();
            }
           
            private function setDefault():void{
                lstColumns.selectedIndices=[0,1,2,3];
                hideShowColumns();
            }
           
            private function handleDivderRelease():void{
                if(counter == 0){
                    controlBox.width =0
                }else if(counter == 1){
                    controlBox.width =120
                }
                counter = (counter +1)%2;
            }
           
        ]]>
    </mx:script>
   
    <mx:vbox id="controlBox" height="100%" width="120" maxWidth="120"  verticalGap="0" horizontalScrollPolicy="off">
        <mx:label text="Selected columns" fontWeight="bold" />
        <mx:list height="100%" width="120" id="lstColumns" dataProvider="{conDataProvider}"
                 labelField="label" borderColor="#000000"
                 allowMultipleSelection="true" click="hideShowColumns()"
                 selectedIndices="[0,1,2,3]"/>
        <mx:textarea wordWrap="true" selectable="false" editable="false" borderStyle="none"
                     text="For multiple selection use ctrl/shift keys" width="120" />
        <mx:spacer height="5" />
        <mx:button label="Select All"  width="100%" click="selectAll()"/>
        <mx:button label="Default"  width="100%" click="setDefault()"/>
        <mx:button label="Clear All" width="100%" click="clearAll()"/>
    </mx:vbox>
    <mx:vbox height="100%" width="100%">
        <mx:datagrid height="100%" id="ResultGrid" selectedIndex="0" enabled="true" selectable="true" creationComplete="init()">
            <mx:columns>
                <mx:datagridcolumn headerText="col1" dataField="c1" visible="true" />
                <mx:datagridcolumn headerText="col2" dataField="c2" visible="true" />
                <mx:datagridcolumn headerText="col3" dataField="c3" visible="true" />
                <mx:datagridcolumn headerText="col4" dataField="c4" visible="true" />
                <mx:datagridcolumn headerText="col5" dataField="c5" visible="false" />
                <mx:datagridcolumn headerText="col6" dataField="c6" visible="false" />
            </mx:columns>
        </mx:datagrid>
    </mx:vbox>
</mx:hdividedbox>
</mx:application>


20
May 09

Remove “Flex Data Visualization Trial” using actionscript

I did a small hack in the Flex charting code and removed the Trial message from the Charting component by writing 1 simple actionscript lines.

what you need to do is in the creationcomplete of any charting component write the following code

1
2
3
4
5
6
7
8
9
private function removeTrialMsg():void{ 
          var arra : Array = new Array();
            for(var i:int =0;i&lt;this.numChildren;i++){
               arra.push(this.getChildAt(i));
            }

// the above 4 lines are just to check  what r the childs added
(this.getChildAt(this.numChildren-1) as TextField).htmlText = " ";
}

we  tried to set visible false but that dint work we also tried to remove the textfield child alltogether  but that too dint work but finally it was the html text property of the textfield that gave way.

now you can also add your custom  trial message to your application :)

just replace the blank with your text for example:

1
2
3
private function removeTrialMsg():void{ 
      (this.getChildAt(this.numChildren-1) as TextField).htmlText = "this is TRIAL";
}

But its better that you buy your own licence key for charting. The above example was basically for educational purpose. have fun :)

trial