Flash Sample Implementation with components - Anychart Flash Chart Component

You can use AnyChart with Flash components in your Flash applications. Please use the following tutorial to add AnyChart in the window.

1. Create new Flash document
2. Create new MovieClip in the library, nam it 'chartContainer'
3. Open 'Linkage properties' for MovieClip (right-click on movie clip in the library, press 'Linkage...')
4. Check 'Export for action script'
5. Set identifier as 'chartContainer'
6. Open 'chartContainer' MovieClip
7. Open Actions-Frame window (press F9 or click Window -> Actions)
8. Write the following code in the action window:

//create movieClip for holding chart
var chartContainer:MovieClip = this.createEmptyMovieClip('chartContainer',this.getNextHighestDepth());

//create string with xml
var xmlSource:String = "<?xml version='1.0'?><root><type><system><refresh enabled='yes'/></system><chart type='Stacked 2DColumn'><animation enabled='yes' speed='30' type='step' appearance='size'/><values decimal_places='3' rotation='-90' x_offset='-8'> <font type='verdana_embed_tf' color='0xFDF6E6'/> </values> <names show='no' /> <hints enabled='yes' width='100' height='50' auto_size='no' horizontal_position='center' vertical_position='top' text='{VALUE}'></hints> <column_chart block_space = '10' column_space = '10' left_space = '10' right_space = '10' up_space = '70' down_space = '0'> <border enabled='no'/> <block_names> <font size='8' type='Verdana' color='White'/> </block_names> </column_chart> </chart> <workspace> <name text='U.S. Population Growth by Race'> <font color='White' type='Verdana'/> </name> <base_area enabled='no' /> <chart_area x='30' y='30' deep='4'> <background color='Gray' type='gradient' gradient_type='linear'> <colors> <color>0xC9D1DD</color> <color>0x8591A1</color> </colors> <alphas> <alpha>100</alpha> <alpha>100</alpha> </alphas> <ratios> <ratio>0</ratio> <ratio>0xFF</ratio> </ratios> <matrix x='0' y='0' w='550' h='400' r='1.57'/> </background> </chart_area> </workspace> <legend enabled='yes' x='425' y='68'> <values enabled='no'/> <scroller enabled='no'/> <header names='Groups'/> <border enabled='no'/> <background enabled='no'/> </legend> </type> <data> <block name='1800-20'> <set value='78' name='Group 1' color='0xFDF6E6'/> <set value='82' name='Group 2' color='0xFFC080'/> </block> <block name='1820-40'> <set value='62' color='0xFDF6E6'/> <set value='80' color='0xFFC080'/> </block> <block name='1840-60'> <set value='55' color='0xFDF6E6'/> <set value='90' color='0xFFC080'/> </block> <block name='1860-80'> <set value='48' color='0xFDF6E6'/> <set value='61' color='0xFFC080'/> </block> <block name='1880-1900'> <set value='36' color='0xFDF6E6'/> <set value='55' color='0xFFC080'/> </block> <block name='1900-20'> <set value='18' color='0xFDF6E6'/> <set value='40' color='0xFFC080'/> </block> <block name='1920-40'> <set value='25' color='0xFDF6E6'/> <set value='25' color='0xFFC080'/> </block> <block name='1940-60'> <set value='48' color='0xFDF6E6'/> <set value='35' color='0xFFC080'/> </block> <block name='1960-80'> <set value='25' color='0xFDF6E6'/> <set value='40' color='0xFFC080'/> </block> <block name='1980-00*'> <set value='33' color='0xFDF6E6'/> <set value='15' color='0xFFC080'/> </block> </data> <objects> <text text='View XML file for this chart' auto_size='yes' x='10' y='380' url='./Stacked-2D-Column.xml'> <font color='White' size='10' align='center' type='Verdana'/> </text> <text text='Source: Statistical Abstract of the United States, 1998. Historical Abstract of the United States' auto_size='yes' x='2' y='340'> <font type='Verdana' size='9' color='White'/> </text> </objects></root>";

//create AnyChart object instance
var anyChart:AnyChart = new AnyChart(chartContainer);
//override onLoad method
anyChart.onLoad = function():Void {
//set chart xml
this.setXMLSourceAsString(xmlSource);
}
//set swf
anyChart.setSWF('Stacked2DColumn.swf');
stop();

9. Store AnyChart.as in the same folder (FLA file folder).
10. Store Stacked2DColumn.swf in the same folder (FLA file folder).
11. Add Window component to library (drag it from Components panel to Library)
12. Open first frame of the root movie
13. Open Actions-Frame window (press F9 or click Window -> Actions)
14. Write the following code in the action window:

import mx.managers.PopUpManager;
import mx.containers.Window;

var win = PopUpManager.createPopUp(_root, Window, true, {closeButton:true, contentPath: 'container'});
function click(evt){
evt.target.deletePopUp();
}
function complete(evt) {
evt.target.setSize(550,400);
}
win.addEventListener("click", this);
win.addEventListener("complete",this);
stop();

15. Press Ctrl + Enter.

Note:
If you want to change a chart data you should use AnyChart.setXMLDataAsString method.
If you want to change a chart appearance you should use AnyChart.setXMLSourceAsString method.

Final

Now you can use AnyChart Flash Component into your own Flash application.
Download .fla file: componentsSample.fla
View how it works: componentsSample.swf

Copyright ©2007 AnyChart.Com All rights reserved.