#31 data load sequence bug in action script/javascript interace

open
nobody
None
5
2008-07-14
2008-07-14
No

In main.as, the action script assumes that the user does not want to load chart data by calling load from swfobject. I had to return an empty string from open_flash_chart_data() in order to prevent json parsing error. Search for error below for work around.

The software should check to see if the user has called .load on the swfobject before resorting to fetching over a URL.

Using load will work much better for me because I already have the data I need to chart in javascript data objects. Not using a URL reduces one request per chart object. Since I have many charts per page, this reduces network overhead substantially.

<script type="text/javascript">

function ofc_ready() {

obj = swfobject.getObjectById("ofc"); // whatever div id you used when calling embedswf()
if (obj) {
obj.load('{"title":{"text":"hello1"}, "x_axis":{"max":6},"elements":[{"type":"line","text":"hey","font-size":10,"values":[5,8,9,4,7,8]}]}');
}
obj = swfobject.getObjectById("my_chart");
var str = '{"title":{"text":"Portreath beach","style":"{color: #736AFF; font-size: 14;}"},"x_legend":{"text":"Waves in Feburary","style": "{color: #736AFF; font-size: 14;}"},"y_legend":{"text": "Wave height (cm)","style": "{color: #736AFF; font-size: 12;}"},"elements":[{"type":"line","colour":"#87421F","width":3,"values" : [1.5,1.69,1.88,2.06,2.21,2.34,2.43,2.48,2.49,2.47,2.40,2.30,2.17,2.01,1.83,1.64,1.44,1.24,1.05,0.88,0.74,0.62,0.54,0.50,0.50,0.54,0.61,0.72,0.86,1.03,1.22,1.41,1.61,1.81,1.99,2.15,2.29,2.39,2.46,2.49]}],"y_axis":{"max":3,"colour": "#FF0000","grid-colour": "#FF0000"},"x_axis":{"steps": 4},"bg_colour": "#E0E0FF"}';
if (obj) {
obj.load(str);
}
}

// Called from Flash - passes data back to flash as part of load
open_flash_chart_data = function() {

return(''); // have to return an empty string or else get json parse error in flash
//str = '{ "y_axis":{"min":6,"max":13,"colour":"#FF0000","grid-colour": "#FF0000"},"y_legend":{"text":"in %","style": "{color: #736AFF; font-size: 15;}"},"x_axis":{"max":6},"elements":[{"type":"line","text":"ROE","font-size":10,"values":[11,11.5,12,12.5,7,10]}]}';
//return(str);

};

var flashvars = false;
var params = {
allowScriptAccess: "always"
};
var attributes = {
id: "ofc",
name: "ofc"
};

swfobject.embedSWF("../open-flash-chart/open-flash-chart.swf", "ofc", "150", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes);
var attributes = {
id: "my_chart",
name: "my_chart"
};
swfobject.embedSWF("../open-flash-chart/open-flash-chart.swf", "my_chart", "150", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes);

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks