Seems to be a scope issue. Use Delegate (mx.utils.Delegate) to fix that :
allSenators_btn.onRelease = Delegate.create(this, colorAllStates);
This will call the colorAllStates function in the right scope, not in
the scope of your button (or more precisely in the scope of onRelease),
wich it is doing in the code you have now.
Make a search on Delegate in the list Archives and you'll have plenty of
more detailed explanations on what it does.
HTH
Alain
Marjorie Roswell wrote:
By the way, here's a picture of this.
http://www.margieroswell.com/concerts/flash_button_issues.jpg
The map with colors is when all the code is inside the OnLoadCongress
function. But when I create buttons I get nothin'. Seems that the
numPeople
variable is accessible to the colorAllStates function. But the array
of XML
nodes (Senators) isn't.
Insight welcome!
On 5/5/07, Marjorie Roswell <[EMAIL PROTECTED]> wrote:
When the whole coloring routine is inside the OnLoadCongress
function, no
problem. But when I put it on a button (the allSenators_btn), it
can't see
the data.
When I add "_global." before the people:Array declaration I get an error
message.
As in, this yields an error:
var _global.people:Array = XPathAPI.selectNodeList(this.firstChild,
"/people/[EMAIL PROTECTED]'Sen.']");
(Also, can't figure out where "ff" is coming from (when this runs
successfully inside the aOnLoadCongress function, but that's another
question.) Seems if I'm setting things to "ff0000" and "0000ff" that
nothing
should turn out to be "ff."
FYI: The data source on this is a subset of
"people.xml<http://www.govtrack.us/data/us/110/repstats/people.xml>"
from here:
http://www.govtrack.us/source.xpd
//I want to color every senator on the various committees,
// and provide a mouseover popup with more info about the Senator.
// For now I'm just doing coloring by party.
// Red = Two Republican Senators
// Blue = Two Democratic Senators
// Purple = one of each
// How do I get the XML to be accessible by the allSenators_btn?
// Just slapping "_global." before the people:Array declaration
yields an
error message.
var congress_xml = new XML();
congress_xml.ignoreWhite = true;
congress_xml.onLoad = OnLoadCongress;
allSenators_btn.onRelease = colorAllStates;
import mx.xpath.XPathAPI;
function OnLoadCongress(success) {
trace("started");
var people:Array = XPathAPI.selectNodeList(this.firstChild,
"/people/[EMAIL PROTECTED]'Sen.']");
numPeople = people.length;
trace(numPeople + " Senators");
}
trace("about to load XML");
congress_xml.load("CurrentCongress.xml");
function colorAllStates() {
var people:Array = XPathAPI.selectNodeList(this.firstChild,
"/people/[EMAIL PROTECTED]'Sen.']");
//allSenators_btn.onRelease = function() {
//if (success) {
trace("button pressed");
trace(numPeople);
// }
var stateparty:Array = new Array();
for (n1=0; n1<numPeople; n1++) {
//purple for state with two parties;
mycolor = new Color(people[n1].attributes.state+"_mc");
mycolor.setRGB(0x9900cc);
}
for (n1=0; n1<numPeople; n1++) {
stateparty[people[n1].attributes.state+"_mc"] = 0;
trace(people[n1].attributes.state+"_mc");
if (people[n1].attributes.party == "Democrat") {
mycolor = new Color(people[n1].attributes.state+"_mc");
switch (mycolor.getRGB().toString(16)) {
case "9900cc" :
trace("it was purple");
mycolor.setRGB(0x0000ff);
trace(mycolor.getRGB().toString(16));
break;
case "ff0000" :
trace("it was red");
mycolor.setRGB(0x9900cc);
trace(mycolor.getRGB().toString(16));
break;
default :
trace("it was some other color");
trace(mycolor.getRGB().toString(16));
break;
}
}
if ((people[n1].attributes.party) == "Republican") {
mycolor = new Color(people[n1].attributes.state+"_mc");
switch (mycolor.getRGB().toString(16)) {
case "9900cc" :
trace("it was purple");
mycolor.setRGB(0xff0000);
trace( mycolor.getRGB().toString(16));
break;
case "0000ff" :
trace("it was red");
mycolor.setRGB(0x9900cc);
trace(mycolor.getRGB ().toString(16));
break;
default :
trace("it was maybe ff, or some other color");
trace(mycolor.getRGB().toString(16));
break;
}
}
}
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com