简体   繁体   English

在特定条件下修改颜色actionscript-3

[英]Modify colours on certain condition actionscript-3

I have a large XML file which I have loaded into actionScript, it basically is a interactive infograph that I want the user to be able to distinguish between values which are estimates and projections. 我有一个很大的XML文件,已将其加载到actionScript中,它基本上是一个交互式信息图,我希望用户能够区分值是估计值还是预测值。 Therefore thats why I want to be able to change the "beginfill" colour on this condition. 因此,这就是为什么我希望能够在这种情况下更改“开始填充”颜色的原因。

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

Here is a basic outline of my XML data, where I want to be able to take the value of the year attribute. 这是我的XML数据的基本概述,我希望能够获取year属性的值。

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

This is where I declare my bar chart values which I want to change colour when the year is beyond 2013. 我在此处声明条形图值,当年份超过2013年时,我想更改其颜色。

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;
mcFGraphics.beginFill(0x660066,1);
mcFGraphics.drawRect(graphX+mfGap,(graphY-(i*cellHeight))-    
cellHeight,mcF.popValue/scaleValue,cellHeight);
mcFGraphics.endFill()

Iam not sure on the correct way to do this and any help would be great. 我不确定执行此操作的正确方法,任何帮助都会很大。

Don't you already have every piece of code you need? 您是否已经拥有所需的每一段代码? You posted them in the question. 您在问题中张贴了它们。

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.attribute("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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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