Since I had a day off, I decided to work on converting my old Flex Examples to the new Flex 4. As stated in a previous post, the new Flex 4 breaks Degrafa and Degrafa seems to be defunct now. Most of the drawing functions are handled with spark and sprite functions, but little things like arcs and line repeaters are not. So where before it was easy enough to create a repeating line in Degrafa, now I have to do a loop to create the lines needed. Well, in this case, instead of drawing lines, I’m drawing rectangles. While it might seem simple at first just to draw a bunch of rectangles together to create a grid, there is a little trickiness to it. You can have to account for the size of the total grid, based on the number of columns, rows and the grid box size. And you also have to use both the column and row count value to draw the correct number of rows and columns and at the right size. It is all just a matter of thinking about it for a few moments and then having an “ah ha!” moment. Another little quirk with the components is that when you add a visual element, it puts it in the center of the group component. On the Egg Timer, I just left it there for now because it worked for what I needed. I might change it later. But for the LineGrid, it made for it not to line up correctly. So, before I start drawing the rectangles, I had to determine the actual 0,0 location first. It also took a couple tries to make sure I was using the right zero.
// Find the actual 0,0 start var actualZeroX:int = -1 * ((columnCount * boxSize) * .5); var actualZeroY:int = -1 * ((rowCount * boxSize) * .5);
One good thing about the new components, is that when you use the declarations, it is the same as creating a set function, which means less code. I simply added declarations for the column and row counts, then put those values where I need them. When I use the LineGrid component I add the values I need just like any other attribute.
<components:LineGrid id="lineGrid1" rowCount="5" columnCount="5" boxSize="50" lineThickness="4" lineColor="0x009900" />
Here is the example showing a grid with equal columns and rows and then two other grids with column or rows determined by the size of the application.