October 2nd, 2008
Using flash to increase social networking application portability
It’s no secret that in the group of major social networking containers they all implement their own set of rules on how developers may interact with their applications, even those “OpenSocial” compliant containers usually don’t implement the full standards body. This problem usually gives developers a great deal of stress when it comes time to move their application to another container.
For much of the high animation, interactive components flash is an excellent medium to decrease the time that you, the developer, will have to spend adjusting your app to get it working perfectly for a new container. In our case, we used the Yahoo! ASTRA library to replace some of our graphing components. We passed a JSON string to the flash object, used a JSON serialization library to parse the data and then used those data structures to build out our components.
We wanted to display a graph detailing positive versus negative voting with an overall vote line running through the middle. Below is a stripped version of the code base we used to initialize our graphing utility. The pieces that have been removed are those that handled the parsing of the inputted voting structures in order to provide the graphing point data providers with dynamic results:
import com.yahoo.astra.fl.charts.*; //astra library import com.yahoo.astra.fl.charts.series.*; //astra library //create a new chart area var chart:StackedBarChart = new StackedBarChart(); chart.setStyle("textFormat", new TextFormat("Arial", 12, 0x2c6076, true)); this.addChild(chart); //create astra bar series for positive votes var upBars:BarSeries = new BarSeries(); upBars.displayName = "Positive"; upBars.dataProvider = [5,6,3,2]; upBars.alpha = 0.7; //create astra bar series for negative votes var downBars:BarSeries = new BarSeries(); downBars.displayName = "Negative"; downBars.dataProvider = [-3,-2,-4,-4]; downBars.alpha = 0.7; //create astra line series for total (positive - negative votes) var totalLine:LineSeries = new LineSeries(); totalLine.displayName = "Total"; totalLine.dataProvider = [2,4,-1,-2]; //set chart data and styles this.chart.dataProvider = [upBars, downBars, totalLine]; this.chart.categoryNames = choiceList; //where choiceList is an array of choices this.chart.setStyle("verticalAxisLabelDistance", 10); this.chart.setStyle("horizontalAxisLabelDistance", 10); this.chart.setStyle("seriesMarkerSkins", [,,bullet]); this.chart.setStyle("seriesColors", [0x66e366,0xff6675,0x2c6076]);
All of the tools we used for this application may be downloaded for free:
Get: ASTRA Library
Description: A library of flash objects that may be used to build out dynamic components and applications. This was the backbone of our graph.
Get: JSON Serialization Library (corelib download)
Description: A parsing utility that will accept a JSON string and convert it to an ASON structure to allow parsing. Be careful with the data you input into this, all key value pairs must be wrapped in double quotes in order to parse correctly, single quotes or bare values will result in a parsing error.
– Jonathan LeBlanc