Recent work & Cross Domain discoveries

7 04 2009

The Sun workThere have been no posts from me for a while as I’ve been building the AS3 carousel section (eBay items) and a series of DoubleClick Ads utilising Twitter feeds in banners and Ebay listings in banners too.  The ads are in AS2 as the DoubleCick TABS system can’t yet take AS3 FYI (coming soon, Cheers Haden for the inside info!). This is all for The Sun Help for Heroes campaign where Ebayers can apply to become sellers and then donate their profits of the items they sell directly to the campaign. We’ve got loads of Celebrities to donate items too and there is a branded hub site pulling all this activity together live within eBay at:

In my rummagings on Cross Domain I discovered this good hack for accessing the pixels from Video on distributed CDN’s:

More posts soon hopefully although my day to day link posting is all being done via Twitter these days so follow along if you’re interested in these things. I am endeavouring to keep my microblogging professional rather than letting you know I am ‘on the bus’/'popped to the shop’ etc so Flash goodies are promised  ;)



PureMVC & Flash Develop basic Kuler API Demo & Source

7 01 2009

I was looking for some basic working examples of PureMVC framework based apps to get my head round the Mediator Interface stuff and found a lovely demo over on Josh Weatherspoon’s blog. I’m not trying to claim I wrote this, just rejigged it so you can use Flash Develop & the Flash IDE not Flex (Hooray!) and if you do too you’ll find this a heck of a lot easier to understand as it’ll compile straight away.  I also updated it for the latest Kuler API (colour swatch generator)

Pure MVC Example

Click the above for a demo & grab the source inc FlashDevelop 3 Project File & bundled non SWC PureMVC libs here.

Cheers Josh, nice one



Dalston Oxfam weekly tape rips

15 04 2008

Totally off technological topic but found an excellent blog of a guy who digitizes obscure cassettes from Dalston Oxfam…

Oxfam Tunes

Good work mate, that’s ace :)



Final Flash Just Giving Parser

12 12 2007

Final Just Giving Example

Right so after several versions of this I finally have a nice class based AS2 version that’s optimised for performance and grabs the full data set. Thanks to all the team at Glue who worked on our Christmas card that inspired this research and also to Rich at Just Giving for his invaluable assistance and for amending their crossdomain.xml file to allow us Flash Devs access to their lovely RSS feeds:

FLA & com folder for download:

Download FLA

[code lang="actionscript"]

class com.glue.xmas.ui.JustGiving extends MovieClip {

// Class assets
private var serverStringPath:String = "http://www.justgiving.com/rss/getfundraisingpage.asp?eventgivinggroupid=";
private var jgGroupID:String;
private var xmlIn:XML;
private var xmlOut:XML;
private var updateJustGivingObj:Object;
private var updateJustGivingInterval;
private var pollSeconds:Number;
// On stage asset declarations
private var justGiving_mc:MovieClip;
private var target_txt:TextField;
private var total_txt:TextField;
private var online_txt:TextField;
private var offline_txt:TextField;
private var giftaid_txt:TextField;
// Temporary conversion assets
private var rcArr:Array;
private var rcStr:String;
private var t_arr:Array;
private var t_arr2:Array;
private var t_pounds:Number;
private var t_pence:Number;
private var t_total:Number;
private var dStr_init:String;
private var dStr_arr:Array;
private var dStr_arr2:Array;;
private var dStr_arr3:Array;
// Core Variable - with Public Getter/Setters
private var currentTarget:Number;
private var currentTotal:Number;
private var currentOnline:Number;
private var currentOffline:Number;
private var currentGiftAid:Number;

function JustGiving(){
// Poll secs & Just Giving Group ID
init(10, "963699");
}

private function init(secs:Number, groupID:String):Void{
pollSeconds = secs;
jgGroupID = groupID;
justGiving_mc = this;
setRepeat(pollSeconds, justGiving_mc, true);
hide();
}

//////////////////////////////////////////////////////////////////
// Hide & Show - Getters and Setters //
//////////////////////////////////////////////////////////////////

private function show():Void {
justGiving_mc._visible = true;
}
private function hide():Void {
justGiving_mc._visible = false;
}

public function set target(newTarget:Number):Void {
currentTarget = newTarget;
}
public function get target():Number {
return currentTarget;
}
public function set total(newTotal:Number):Void {
currentTotal = newTotal;
}
public function get total():Number {
return currentTotal;
}
public function set online(newOnline:Number):Void {
currentOnline = newOnline;
}
public function get online():Number {
return currentOnline;
}
public function set offline(newOffline:Number):Void {
currentOffline = newOffline;
}
public function get offline():Number {
return currentOffline;
}
public function set giftaid(newGiftAid:Number):Void {
currentGiftAid = newGiftAid;
}
public function get giftaid():Number {
return currentGiftAid;
}

//////////////////////////////////////////////////////////////////////////////////
// Setup Interval Set and Clear to control update period of live RSS data //
// //
// Seconds to leave between updates //
// Optional boolean - whether to execute instantly as well as on interval //
//////////////////////////////////////////////////////////////////////////////////

private function setRepeat(repeatTime:Number, mcScope:MovieClip, alsoCallOnInit:Boolean):Void {
updateJustGivingObj = new Object();
updateJustGivingObj.updateFromRSS = function():Void {
//On Interval - Parse RSS
trace("Requesting Fresh RSS Data...");
mcScope.parseJGRSS(mcScope.serverStringPath, mcScope);
}
updateJustGivingInterval = setInterval(updateJustGivingObj, "updateFromRSS", repeatTime*1000);
// Optional Instant Execute
if(alsoCallOnInit == true){
updateJustGivingObj.updateFromRSS();
}
}

private function clearRepeat():Void {
clearInterval(updateJustGivingInterval);
}

private function onJGFeedParse():Void {
target_txt.text = ""+target;
total_txt.text = ""+total;
online_txt.text = ""+online;
offline_txt.text = ""+offline;
giftaid_txt.text = ""+giftaid;
show();
}

//////////////////////////////////////////////////////////////////////////////////
// Main Parsing function and 2 String & Datatype Manipulation functions used by //
// removeCommas() //
// jgFeedStrToNum() //
// parseJGRSS() //
//////////////////////////////////////////////////////////////////////////////////

private function removeCommas(args:String):String {
trace("Removing Comma's from tridecimal string "+args);
// Split the string into tridecimal strings and reconcatenate without the commas
rcArr = args.split(',');
var rcStr:String = "";
for (var i=0; i rcStr += rcArr[i];
}
return rcStr;
}

private function jgFeedStrToNum(args:String):Number {

// Remove any commas as Just Giving add them at triddecimals e.g "£1,056,234"
if (args.indexOf(',') != -1) {
args = removeCommas(args);
}
// Split Donations string into Pounds/Pence - (or Dollars/Cents)
t_arr = args.split('.');
// Remove any trailing space from after the Pence/Cents string
t_arr2 = t_arr[1].split(' ');
var t_pounds:Number = new Number(t_arr[0]);
var t_pence:Number = new Number(t_arr2[0]);
//trace("Pounds "+t_pounds+" Pence "+t_pence+" Pence in Pounds "+(t_pence/100));
var t_total:Number = t_pounds+(t_pence/100);

return t_total;
}

private function parseJGRSS(jgRSSUrl:String, mcScope:MovieClip) {
var xmlIn:XML = new XML();
var xmlOut:XML = new XML();
xmlIn.ignoreWhite = true;

xmlIn.onLoad = function(success) {
if (success) {
//////////////////////////////////////////////////////////////////////////////////////////////
// PROCESS THE "Item Description" NODE TO GET ALL THE FINANCE TOTALS //
//////////////////////////////////////////////////////////////////////////////////////////////

trace("Loaded Feed & Parsing RSS...");

var dStr_init:String = this.firstChild.childNodes[0].childNodes[6].childNodes[2].childNodes[0].nodeValue;

// Split XML node string by html list end symbol
dStr_arr = dStr_init.split('

');

// Get Fundraising Page Target :
dStr_arr2 = dStr_arr[0].split(';');
currentTarget = mcScope.jgFeedStrToNum(dStr_arr2[1]);
//trace("currentTarget = "+currentTarget);
//mcScope.target_txt.text = currentTarget;
mcScope.target = currentTarget;

// Get Total donations to date :
dStr_arr2 = dStr_arr[1].split(';');
currentTotal = mcScope.jgFeedStrToNum(dStr_arr2[1]);
//trace("currentTotal = "+currentTotal);
//mcScope.total_txt.text = currentTotal;
mcScope.total = currentTotal;

// Get Online donations to date :
dStr_arr2 = dStr_arr[2].split(';');
currentOnline = mcScope.jgFeedStrToNum(dStr_arr2[1]);
//trace("currentOnline = "+currentOnline);
//mcScope.online_txt.text = currentOnline;
mcScope.online = currentOnline;

// Get Amount raised offline :
dStr_arr2 = dStr_arr[3].split(';');
currentOffline = mcScope.jgFeedStrToNum(dStr_arr2[1]);
//trace("currentOffline = "+currentOffline);
//mcScope.offline_txt.text = currentOffline;
mcScope.offline = currentOffline;

// Get The UK Gift Aid Reclaimed :
dStr_arr2 = dStr_arr[4].split(';');
dStr_arr3 = dStr_arr2[1].split('');
currentGiftAid = mcScope.jgFeedStrToNum(dStr_arr3[0]);
//trace("currentGiftAid = "+currentGiftAid);
//mcScope.giftaid_txt.text = currentGiftAid;
mcScope.giftaid = currentGiftAid;

mcScope.onJGFeedParse();

} else {
trace("RSS Load Failed");
}
};
xmlOut.sendAndLoad(jgRSSUrl+jgGroupID, xmlIn);
}
}

[/code]



Flash justgiving.com RSS Parse v2

10 12 2007

BananasUpdated the Flash Just Giving method to use XML.sendAndLoad instead of LoadVars and I’ve also included the Pence/Cents calculations if you need to do Maths on the returned value. You should be able to work out from this whatever properties you need from the RSSXML: all my source is below:

[code lang="actionscript"]

// Just Giving RSSXML Parsing V2
var xmlIn:XML = new XML();
var xmlOut:XML = new XML();
xmlIn.ignoreWhite = true;
xmlIn.onLoad = function(success) {
if (success) {

// HERES ALL THE PROPERTIES OF THE RSSXML
/*
trace("Title "+this.firstChild.childNodes[0].childNodes[0].childNodes[0]);
trace("Link "+this.firstChild.childNodes[0].childNodes[1].childNodes[0]);
trace("Description "+this.firstChild.childNodes[0].childNodes[2].childNodes[0]);
trace("Language "+this.firstChild.childNodes[0].childNodes[3].childNodes[0]);
trace("Last Build Date "+this.firstChild.childNodes[0].childNodes[4].childNodes[0]);
trace("TTL "+this.firstChild.childNodes[0].childNodes[5].childNodes[0]);
trace("Item Title "+this.firstChild.childNodes[0].childNodes[6].childNodes[0].childNodes[0]);
trace("Item Link "+this.firstChild.childNodes[0].childNodes[6].childNodes[1].childNodes[0]);
trace("Item Description "+this.firstChild.childNodes[0].childNodes[6].childNodes[2].childNodes[0]);
trace("Item Publish Date "+this.firstChild.childNodes[0].childNodes[6].childNodes[3].childNodes[0]);
*/
// HERES HOW TO PROCESS THE TO GET THE CURENT DONATIONS TOTAL

var donationStr:String = this.firstChild.childNodes[0].childNodes[6].childNodes[0].childNodes[0].nodeValue;
//testing only - donationStr = "So far this page has raised £980.07 "

// Split XML node string by pound sign (change to dollars $ if your currency is US)
arr = donationStr.split('£');

//At this point - if all you need is a string just use this..
trace("Donations as a String = "+"£"+arr[1]);
// However if you want a Number you can do Maths on you'll have to do a touch more...

// Split Donations string into Pounds/Pence - (or Dollars/Cents)
arr2 = arr[1].split('.');
// Remove any trailing space from after the Pence/Cents string
arr3 = arr2[1].split(' ');

var tdPounds:Number = new Number(arr2[0]);
var tdPence:Number = new Number(arr3[0]);
//trace("Pounds " + tdPounds + " Pence "+tdPence + " Pence in Pounds "+(tdPence/100));
var totalDonations:Number = tdPounds + (tdPence/100);

trace("Donations as a Number = " + totalDonations);

} else {
trace("RSS Load Failed");
}
};
// http://www.justgiving.com/gorillarob
//xmlOut.sendAndLoad("http://www.justgiving.com/rss/getfundraisingpage.asp?eventgivinggroupid=499910",xmlIn);
// http://www.justgiving.com/gluexmas
xmlOut.sendAndLoad("http://www.justgiving.com/rss/getfundraisingpage.asp?eventgivinggroupid=963699",xmlIn);

[/code]

Example FLA for download:
Download FLA



Flash AS2 Justgiving.com RSS Parsing

5 12 2007

Here’s a quick method of parsing your justgiving.com RSS feed in AS2

As a little background – here is my Just Giving Gorilla Run 2007 page and here’s the corresponding RSS feed

Bananas

This AS2 Actionscript function returns the total online donations as a Number, it’s a bit quick and dirty but will do a job ;)

[code lang="actionscript"]

function parseRSSForTotalOnlineDonations(justGivingURL:String, justGivinGroupID:String) {

var jgGrID = justGivinGroupID;
var jgStr = justGivingURL+jgGrID;
var rssSend_lv:LoadVars = new LoadVars();
var rssReply_lv:LoadVars = new LoadVars();

rssReply_lv.onLoad = function(success:Boolean) {
if (success) {

var rssXML:XML = new XML(this);
var st:String = new String(rssXML.childNodes[0]);
arr = st.split('Total');
st2 = unescape(arr[1]);
arr2 = st2.split('');
st3 = unescape(arr2[0]);
arr3 = st3.split('#');
st4 = arr3[1];
arr4 = st4.split(';');
st5 = unescape(arr4[1]);
arr5 = st5.split('.');
st6 = unescape(arr5[0]);
var totalDonations:Number = new Number(st6);

trace(totalDonations);

} else {
trace("Connection Failed!");

}
};

rssSend_lv.sendAndLoad(jgStr, rssReply_lv, GET);

}

parseRSSForTotalOnlineDonations("http://www.justgiving.com/rss/getfundraisingpage.asp?eventgivinggroupid=","499910");

[/code]

As ever if this helps you please distribute this link via any of the provided Bookmarking tools. Cheers.