简体   繁体   中英

How do you to test an if statement in actionscript-3?

So Iam trying to produce an if statement that will change the colour of graphics in as3, my data is coming from a large xml file which works fine I just need that when the value is more than 2013 that a certain condition will happen ie change graphics fill. It is essentially an interactive infograph developed in flash. Below is the outline of the xml file.

<dataset>
<source></source>
<extent></extent>
<scaleFac></scaleFac>
<recordSet year="1982" popTotal="1544545">
<m> //Male
<rd></rd>
<f> //Female
<rd></rd>

My main concern is Iam not sure if Iam correctly querying the xml file to test the condition. So I want to take the recordSet year value ie 1982 and create an if statement that when the year is > 2013 the condition is true, this is what I have so far.

var yearRecord:String = xmlData.recordSet.attribute("year");
if( int(yearRecord) > 2013 )
{...}

and from research I have seen others doing this

var yearRecord:String = xmlData.recordSet.@year;
if( int(yearRecord) > 2013 )
{
color = 0xFF0000;  //projection color
}

So my question is, How can test it to see if the condition is working so I can manipulate the colours. I have tried using trace("true") and changed the year to 2013 but nothing is outputed therefore I think there is something wrong with my if statment. Any help would be appreciated.

*Main Peices of code

function modifyYear(){

var mcF:MovieClip = new MovieClip();
mcF.age=i;
mcF.popValue=xmlData.recordSet[indexYear].f.rd[i].text();
mcF.name="popF"+i
var mcFGraphics:Graphics = mcF.graphics;
var color:Number = 0x660066;  //default color

var yearRecord:String = xmlData.recordSet[0].@year;
if( int(yearRecord) > 2013 )
{
color = 0xFF0000;  //projection color
}

mcFGraphics.beginFill(color,1);  //draw with whatever appropriate color
mcFGraphics.drawRect(graphX+mfGap,(graphY-(i*cellHeight))-    
cellHeight,mcF.popValue/scaleValue,cellHeight);
mcFGraphics.endFill();

}

Well, just put an 'else' there.

var yearRecord:String = xmlData.recordSet[0].@year;
if( int(yearRecord) > 2013 )
{
color = 0xFF0000;  //projection color
}
else {
trace("you did something wrong");
}

EDIT: Why don't you trace the 'yearRecord' variable to see what you are receiving?

just use trace

trace(int(yearRecord) > 2013); 

will return true if it matches, false if it doesn't

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM