Sign in to follow this  
Pallav

Dynamically Changing SWF from Javascript

Recommended Posts

I have a little demo web page that had five buttons on it (Column2D, Column3D, Pie2D, Pie3D, Line). In the past, I have been able to click any button and have the swf change based on which button I clicked. This allowed me to see the same data in 5 different forms.

 

 

 

Today, I decided that I was going to add a Multi Series 3D Column button to the page. Obviously, I would need to load a special XML file for this button due to the fact that the syntax is a little different. However, now I notice that when I click on the Multi Series button I get a JavaScript error that says the object doesn't support the property/method.

 

 

 

Here is the function that I have been using to switch my swf:

 

 

 


function switchChartType(chartType)

{

  chart1.setAttribute('swf', 'http://marks/FusionCharts/charts/' + chartType + '.swf');

  chart1.render('mainChart');

}

 

 

 

chartType is passed in as the name of the actual SWF that is saved on my machine.

 

 

 

Here is the function that I am using to switch my data sources:

 

 

 


function switchSource(toFile)

{

  chart1 = getChartFromId("main_chart");

  if(toFile == "True")

     chart1.setDataURL("/exampleChart.xml");

  else

     chart1.setDataXML(xmlData);

}

 

 

 

toFile indicates whether or not the chart should be loaded from a file (for the Multi-Series chart) or from JavaScript (for the other charts).

 

 

 

For the record, chart1 and xmlData are both global.

 

 

 

The code seems to error when I call chart1's render function. However, this only occurs when the Multi-Series chart is involved. If it is removed, everything is fine. Any thoughts?

Share this post


Link to post
Share on other sites

I don't have a live site to share, but I do seem to have solved the problem. I have created a new JavaScript function for switching the SWF and the data source:

 


function switchChartType(chartType)

{

  chart1 = new FusionCharts('http://marks/FusionCharts/charts/' + chartType + '.swf', 'main_chart', '400', '300', '0', '1');  

  if(chartType != "MSColumn3D")

     chart1.setDataXML(xmlData);

  else

     chart1.setDataURL("/exampleChart.xml");

  chart1.render('mainChart');

}

 

This works for me perfectly. :D

Edited by Guest

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this