Tuesday, February 7, 2012

Flash threads ( native Workers solution )

In Flash Player 12 the programmers can use Threads. The Threads called Workers, and the instances called Promises.
What we need to know about workers: The workers shared nothing, have message passing, and have shared render surface.


Flash thread ( Pseudo Thread solution )

Flash (Action Script) doesn't have (yet) Threads. The answer is simple: the concurency management too complex to an average Flash (or designer) developer. Threads will be available in Flash Player 12, but what we can do until? We can emulate the Threads ( called PseudoThread ).

The Flash Player has only limited thread ( example: request from server with async, event handling, video rendering ), but how can we delegate (or emulate) a Thread? (Not) Simply :) If you run a huge while or for each, you experienced that the UI froze.... Because the Flash Player has frames (and frame times too), so if your code don't fit in a frame time, the Flash can't update the UI.

The solution is: Use PseudoThread, and slice your function to. What is function slicing? If your program do A->B->C->D->E you can split "virtually" 5 segment. If you know, what is the actual segment that need to run, and rebuild the function state ( the variables that use common each segment ), you can pass the A, and some frametime later you can pass the B segment and so on.

Advanced Datagrid groupping tree bug

If you group an AdvancedDatagrid dataprovider with a grouping field, there is a mistake: If you have many rows, and scroll to right to the table, and than group a field, go back to scroll left, but there is an error (or you don't have error, but the tree lost some values). Obviously it is fail.

    <mx:AdvancedDataGrid width="100%" height="240"
            horizontalScrollPolicy="on" verticalScrollPolicy="on" >
        <mx:dataProvider>
            <mx:GroupingCollection2 id="gc" source="{arr_personal_production}" />
        </mx:dataProvider>
      
        <mx:columns>
            <mx:AdvancedDataGridColumn headerText="#" dataField="mppid"/>
            ...
        </mx:columns>
    </mx:AdvancedDataGrid>


Different round, floor, ceil


If you ever use a programming language to calculate something you will use the floor, the ceil, the round functions. It's freaky, but the result of these function differs. Here it is the source codes, and the output results. Funny ActionsScript and obviously Java :)