The
ClassFactory class has a property called 'properties.' This is a hash
table (object) full of key/value pairs that get applied to instances generated
by the ClassFactory as necessary. So in your case, your markup is saying
'create a PieCategoryWedgeRenderer, and when it gets created, assign an array
of PieCategory objects to its categories property as
needed'.
So you
could do this:
var
cf:ClassFactory = new
ClassFactory(PieCategoryWedgeRenderer);
var
tmp:Array = [];
var
pc:PieCategory = new PieCategory();
pc.value =
"Encouraged";
pc.color =
0x99ff99;
tmp.push(pc);
pc = new
PieCategory();
pc.value =
"Acceptable";
pc.color =
0x9999ff;
tmp.push(pc);
...
cf.properties = {
categories: tmp;
}
Alternatively, you could just copy the whole PieCategoryWedgeRenderer
tag and contents from your markup into a separate MXML (call it
MyPCWedgeRenderer.mxml) file to create a pre-customized subclass.
then:
var
cf:ClassFactory = new ClassFactory(MyPCWedgeRenderer);
and you're
done.
Ely.
Sent: Saturday, June 17, 2006 9:39
AM
To: [email protected]
Subject: [flexcoders]
Re: changing out pieSeries.itemRenderer at runtime
Okay, good start. I was thrown off by the help
topic"Flex 2.0 Developer's Guide > Customizing the User Interface >
Using Item Renderers and Item Editors > Creating an item renderer and item
editor". It still uses the old non-setStyle method to set the
itemRenderer.
Now how do I build this in code:
<mx:itemRenderer>
<mx:Component>
<nes:PieCategoryWedgeRenderer>
<nes:categories>
<nes:PieCategory value="Encouraged"
color="#99FF99"/>
&nbs! p;
<nes:PieCategory value="Acceptable"
color="#9999FF"/>
<nes:PieCategory value="Risk"
color="#FFFF99"/>
<nes:PieCategory value="High Risk" color="#FF9999"/>
</nes:categories>
</nes:PieCategoryWedgeRenderer>
</mx:Component>
</mx:itemRenderer>
I've gotten this far:
public var riskRenderer! :ClassFa ctory =
new
ClassFactory(nes.charts.dataRenderers.PieCategoryWedgeRenderer);
Sadly, I'm lost after that. I can't figure
out how to add the categories. Any tips?
--- In [email protected], "Ely Greenfield"
<[EMAIL PROTECTED]> wrote:
>
>
>
> Item Renderer is
a style. so you have to do this:
>
>
>
ps.setStyle("itemRenderer", ... );
>
>
> What do you pass
in as the value?
>
> 1) Passing null doesn't work. You've
overridden the style, so you need
> ot set a new value. The default
value is the class
> mx.charts.renderers.WedgeItemRenderer.
>
> 2) itemRenderers are typed as IFactory. Meaning they need to be
an
> object that implements the IFactory interface. Flex ships with
a
> default IFactory that simply wraps a class, called
ClassFactory.
> So you want to do this:
>
> import mx.charts.rende! rers.WedgeItemRenderer;
>
> ps.setStyle("itemRenderer", new
ClassFactory(WedgeItemRenderer));
>
> you'll probably have to
import ClassFactory too...I don't remember what
> it's package is
(probably mx.core), but you can find it in the AS doc
>
reference.
>
> Ely.
>
>
>
________________________________
>
> From: [email protected] [mailto:
[email protected]] On
> Behalf Of Jason
> Sent:
Friday, June 16, 2006 4:19 PM
> To: [email protected]
> Subject: [flexcoders]
changing out pieSeries.itemRenderer at runtime
>
>
>
> Okay, so I've made an itemRenderer for a pieSeries. But sometimes
I
> want to turn it off. How might I go about that?
>
>
<mx:PieSeries id="ps" field="time"
labelPosition="insideWithCallout"
> labelFunction="getLabel"
> dataProvider="{chartData}" insideLa! belSizeLimit="10"
>
fontSize="10">
> ! <mx:i temRenderer>
> <mx:Component>
>
<nes:PieCategoryWedgeRenderer>
> <nes:categories>
>
<nes:PieCategory va! lue="Encouraged"
> color="#99FF99"/>
>
<nes:PieCategory value="Acceptable"
> color="#9999FF"/>
>
<nes:PieCategory value="Risk"
> color="#FFFF99"/>
>
<nes:PieCategory value="High Risk"
> color="#FF9999"/>
>
</nes:categories>
> </nes:PieCategoryWedgeRenderer>
>
</mx:Component>
> </mx:itemRen! derer>
>
</mx:PieSeries>
>
>
> <
/font>PieCategoryWedgeRenderer is a class I wrote that I mentioned
in
> another thread. So now in some function in the applicatio! n, I want
to
> say:
>
> ps.itemRenderer =
null;
>
> or even
>
>
ps.itemRenderer.categories[0].value = "NewTitle";
>
> I've read
through all the help and can't figure out how I would actually
> do
that. FB says it has no idea what "ps.itemRenderer" is referring to.
>
So that kinda stumps me.
>