David Widaman
posted this on July 20, 2011 11:06 pm
(BETA) The Flash Widget API can be used to create custom widgets using the widget data created in the Topspin platform. Currently, there are three types of widgets that this API supports:
Since Topspin already provides these out of the box widgets, artists and developers may choose to create custom widgets with additional functionality and different UI, but still retain the Topspin event tracking based on campaigns. Using this API will abstract out any of the event logging logic so that is takes place automatically after registering the widget id (See below).
Developers must download the com.topspin.api package and add it to their classpath when compiling their AS3 widgets. The package can be downloaded either in swc format or a .zip file containing the classes and interfaces.
You will need to load in a swf from our CDN (http://cdn.topspin.net/widgets/api/TSWidgetAPI.swf) and cast it as a com.topspin.api.data.ITSWidget.
Once the swf is loaded in, additional operations can take place. The following is an example of how the swf should be loaded into your application:
Loading an ITSWidget
The widget id can be found in the published embed code from any of the 3 widgets types.
For instance, the widget_id can be pulled from the flashvars below:
Streaming Widget Embed Code
Once you have an instance of the ITSWidget in your application, begin by adding listeners forcom.topspin.api.events.TSWidgetEvents and then register your widget id.
Register widget id
After you register and receive a TSWidgetEvent.WIDGET_LOAD_COMPLETE event, you may want to keep track of the campaign_id by using: ITSWidget.getCampaignId(). The campaign id must be sent in with each API call or the current campaign id is used. Use the ITSWidget to access data and perform certain actions against your widget_id.
com.topspin.api.data.ITSWidget
To play an media, audio or video data, you must use the ITSPlaylist interface to ensure that proper event logging take place. The ITSPlaylist manages all the media in any given widget_id whether it be a Streaming Player or E4M. Both AudioData and VideoData implement an ITrackData interface so that loading, playing, seeking and playback functionality is identical regardless of the media type. The following is the it ITSPlaylist interface followed by ITrackData.
com.topspin.api.data.ITSPlaylist
The ITSPlaylist manages a set of ITrackData objects. This interface is implemented by two classes, AudioData and VideoData which are wrappers for Sound and Video flash objects. Using the ITrackData interface, loading, getting info, and playback calls are made simple.
com.topspin.api.data.media.ITrackData
Additional documentation on the methods and such can be found in the source of the com.topspin.api package code. The source code for example project is also included in the .zip file.
Example: Topspin Flash Widget API Playground
Latest source code is available on GitHub:
http://github.com/amehta3000/topspin-flash-widget-api