Dynamic color on xml driven datagrid

Hi professionals.

I have a flash datagrid, that is XML driven, and uses a XML connector and a dataset.
This grid is displaying a price list.

I have been caught in a deadlock regarding how to dynamically set the color for sold objects red.

I have this object: <STATUS></STATUS>

This being sold or available. I would like the status column to check the status tag to see if it is sold or not, and then set the colors green or red respectively.

I have pondered this one for quite some time without figuring out how. Please help!?!?!

doomieAsked:
Who is Participating?
 
ellandrdConnect With a Mentor Commented:
sorry i meant to say this is what your code looks like when indended.  you where missing a some closing }

the second ssegment of code that is indended proper is what it should look like...

sorry if ive confused you with my above
0
 
ellandrdCommented:
Hi doomie,

I appologize for not giving an indepth answer however I think your problem will be easily fixed after reading through the following help guide supplied by Macromedia, Inc.

Customizing the DataGrid component (Flash Professional only)

You can transform a DataGrid component horizontally and vertically during authoring and runtime. While authoring, select the component on the Stage and use the Free Transform tool or any of the Modify > Transform commands. At runtime, use the setSize() method (see UIObject.setSize()). If there is no horizontal scroll bar, column widths adjust proportionally. If column (and therefore, cell) size adjustment occurs, then text in the cells may be clipped.

Using styles with the DataGrid component
You can set style properties to change the appearance of a DataGrid component. The DataGrid component inherits Halo styles from the List component. (For more information, see Using styles with the List component.) The DataGrid component also supports the following Halo styles:

Style
 Description
 
backgroundColor
 The background color can be set for the whole grid or for each column.
 
labelStyle
 The font style can be set for the whole grid or for each column.
 
headerStyle
 A CSS Style Declaration for the column header that can be applied to a grid or column.
 
vGridLines
 A Boolean value that indicates whether to show vertical grid lines (true) or not (false).
 
hGridLines
 A Boolean value that indicates whether to show horizontal grid lines (true) or not (false).
 
vGridLineColor
 The color of the vertical grid lines.
 
hGridLineColor
 The color of the horizontal grid lines.
 
headerColor
 The color of the column headers.
 

If the above table indicates that a style can be set for a column, you can use the following syntax to set the style:

grid.getColumnAt(3).setStyle("backgroundColor", 0xff00aa)

Using skins with the DataGrid component
The skins that the DataGrid component uses to represent its visual states are included in the subcomponents from which the data grid is composed (ScrollPane and RectBorder). For information about their skins, see Using skins with the ScrollPane component and Using skins with the List component.

The rollover and selection underlays, however, use the ActionScript Drawing API. To skin these portions of the data grid while authoring, modify the ActionScript code in the skin symbols in the Flash UI Components 2/Themes/MMDefault/datagrid/ skins states folder in the library of one of the themes FLA files.



If you need any help putting this into practice, let me know.

Cheers

Ellandrd
0
 
doomieAuthor Commented:
I am a step closer now, but had to abandon XMLConnector Dataset in order for the formatting to work.
Here is an example of my code:

function parseXML() {
      myXML = new XML();
      myXML.load("http://www.XXXXXXXXXX.com/html/prisliste.xml");
      myXML.ignoreWhite = true;
      myXML.onLoad = function(success) {
            if (success) {
                  //trace("xml loaded...");
                  makeArray();
            } else {
                  
            }
      };
}
function makeArray() {
      Users = [];
            nodes = myXML.firstChild.childNodes;
      for (i=0; i<nodes.length; i++) {
            Users.push({Leilighet:myXML.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue,
                              BRA:myXML.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue,
                              Innskudd:myXML.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue,
                              Fellesgjeld:myXML.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue,
                              Pris:myXML.firstChild.childNodes[i].childNodes[4].firstChild.nodeValue,
                              fpm:myXML.firstChild.childNodes[i].childNodes[5].firstChild.nodeValue,
                              rfpes:myXML.firstChild.childNodes[i].childNodes[6].firstChild.nodeValue,
                              Status:myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue});
                                    if (myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue == "Solgt")
                                          UserGrid.setCellStyle( i, 7, "textcolor", "0xFF0000" );
                                    {
}

            UserGrid.dataProvider = Users;
      }
}

parseXML();



This works ALMOST perfect, but only almost.

For some reason it formats the text red for a second, blinks and removes the formatting. The formatting reapers when the grid gets focus, (mouseclick or drag the scrollbar)

 Flash can be a joy! Any ideas?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
ellandrdCommented:
function makeArray()
{
      Users = [];

      nodes = myXML.firstChild.childNodes;

      for (i=0; i<nodes.length; i++)
      {
            Users.push(
            {
                  Leilighet:myXML.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue,
                  BRA:myXML.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue,
                  Innskudd:myXML.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue,
                  Fellesgjeld:myXML.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue,
                  Pris:myXML.firstChild.childNodes[i].childNodes[4].firstChild.nodeValue,
                  fpm:myXML.firstChild.childNodes[i].childNodes[5].firstChild.nodeValue,
                  rfpes:myXML.firstChild.childNodes[i].childNodes[6].firstChild.nodeValue,
                  Status:myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue});

                  if (myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue == "Solgt")
                        UserGrid.setCellStyle( i, 7, "textcolor", "0xFF0000" );
                        {
                              
                        }

                  UserGrid.dataProvider = Users;
      }
}


which when the indentation is done proper it should look like this.


function makeArray()
{
      Users = [];

      nodes = myXML.firstChild.childNodes;

      for (i=0; i<nodes.length; i++)
      {
            Users.push(
            {
                  Leilighet:myXML.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue,
                  BRA:myXML.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue,
                  Innskudd:myXML.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue,
                  Fellesgjeld:myXML.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue,
                  Pris:myXML.firstChild.childNodes[i].childNodes[4].firstChild.nodeValue,
                  fpm:myXML.firstChild.childNodes[i].childNodes[5].firstChild.nodeValue,
                  rfpes:myXML.firstChild.childNodes[i].childNodes[6].firstChild.nodeValue,
                  Status:myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue});

                  if (myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue == "Solgt")
                  {
                        UserGrid.setCellStyle( i, 7, "textcolor", "0xFF0000" );
                        {
                              
                        }
                  }      
            }
            
            UserGrid.dataProvider = Users;
      }
}

maybe skippin the if statement might be causing it....

ellandrd
0
 
doomieAuthor Commented:
The code you provided does the job, but only for about half a second. Then the datagrid redraws(?) and and removes all formatting.
I have searched everywhere for a fix, but i am soooo stuck!

Take a look:
http://www.actiweb.no/html/olsen/test.html

The code i have tweaked so far is:

MyText = "xml loading...";
stop();
function parseXML() {
      myXML = new XML();
      myXML.load("http://www.birkebeinerbakken.no/html/prisliste.xml");
      myXML.ignoreWhite = true;
      myXML.onLoad = function(success) {
            if (success) {
                  MyText = "xml loaded...";
                  makeArray();
            } else {
                  MyText = "xml loading...";
            }
      };
}
function makeArray() {
      Users = [];
      nodes = myXML.firstChild.childNodes;
      for (i=0; i<nodes.length; i++) {
            Users.push({Leilighet:myXML.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue, BRA:myXML.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue, Innskudd:myXML.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue, Fellesgjeld:myXML.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue, Pris:myXML.firstChild.childNodes[i].childNodes[4].firstChild.nodeValue, fpm:myXML.firstChild.childNodes[i].childNodes[5].firstChild.nodeValue, rfpes:myXML.firstChild.childNodes[i].childNodes[6].firstChild.nodeValue, Status:myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue});
            if (myXML.firstChild.childNodes[i].childNodes[7].firstChild.nodeValue == "Solgt") {
                  UserGrid.setCellStyle(i, 7, "textcolor", "0xFF0000");
            } else {
                  UserGrid.setCellStyle(i, 7, "textcolor", "0x009933");
            }
      }
      UserGrid.dataProvider = Users;
      _root.UserGrid.dataProvider = Users;
}
parseXML();


Te0
"SuperBaffled"
0
 
doomieAuthor Commented:
Found a slolution :) The problem was in the  UserGrid.dataProvider = Users; statement.
This was set to soon. When i made a timer and populated the grid after all data was loaded, the colors are staying put :)

How do i fix this pointswise now?
0
 
ellandrdCommented:
basically choose my comment on:

Date: 11/06/2006 03:27PM GMT
0
All Courses

From novice to tech pro — start learning today.