Listing 11

void draw_with_clips(SWFSprite *movieclip,float ox,float oy,float xr,
                           float yr,double rot,const char *prefix){
double total=std::accumulate(data.begin(),data.end(),0.0, get_value);
if(total<=0.0)return;
movieclip->add(new SWFAction("_root.createTextField
     ('mo_txt', 1000,0,0,0,0);_root.mo_txt.autosize=true; /
     _root.mo_txt.border=true;_root.mo_txt.background=true; /
     _root.mo_txt.selectable=false;_root.mo_txt._visible=false;")); /
size_t cnt=1;
for(const_iterator i=data.begin();i!=data.end();++i,++cnt){
    double arc=(i->value/total)*M_PI*2;
    SWFSprite *clip=new SWFSprite();
    i->appearance.draw_pie_slice(clip,ox,oy,rot,rot+arc,xr,yr);
    rot+=arc;
    clip->nextFrame();
    SWFDisplayItem *item=movieclip->add(clip);
    char name[64];
    sprintf(name,"%s%d",prefix,cnt);
    item->setName(name);

    char buf[4096];
    sprintf(buf,"%s.onRollOver=function()
       {_root.mo_txt.text='%s';_root.mo_txt._x=_root._xmouse;
        _root.mo_txt._y=_root._ymouse;_root.mo_txt._visible=true;};
        %s.onRollOut=function(){_root.mo_txt._visible=false;};
        ",name,i->label.c_str(),name);
    movieclip->add(new SWFAction(buf));
    }
}