...ndid, the somewhat small but happy love child of Nicolás Delfino. A company specialized in interactive websites and rich media applications, knee deep in actionscript and down with jazz...

Archive for the ‘Tutorials’ Category

Scoreoid – Highscores the easy way

Posted on: September 24th, 2011

Today I got the chance to finally play with the awesome game platform by Almog Design (www.almogdesign.net) called Scoreoid.

What Scoreoid is:

Scoreoid is a non-restrictive, reliable and easy to use gaming platform designed to handle scoring, leaderboards and game management, including advanced functions for multi-platform games such as platform content awareness to advanced player management. Developed by game developers for game developers.

(Info from www.scoreoid.net)

Why Scoreoid:

The reason I´m thrilled about Scoreoid is simply because it lets you cut time on an otherwise potentially time exhaustive part of game development, scores.

With that said I thought I´d write a basic tutorial.

Using Scoreoid:

Getting started with Scoreoid is a breeze, all you really need to do is to sign up (www.scoreoid.com/register) and to add a game, the rest is taken cared of by Scoreoid!

To create a game simply navigate to the dashboard and click on “Add new game”. There´s some basic data you need to enter, nothing weird so I leave that up to you.

There´s actually tons of stuff you can do here, and I do recommend you to check it out, but to get to get started on this tutorial you´ll need 2 things:

An API-key

found under your Account Info.

A Game-ID

found under games and specific for the game you´re working on.

Scoreoid + Flash:

Here´s where the magic happens, no downloads – no nothing.
From here on I´ll show you just the absolute basics needed to get you started on a real world situation.

Please note that his example doesn´t necessary follow best practices and how you end up using this is up to you. Also note that I´m writing this inside a document class.

The Document class (Main.as)

	//SCOREOID - www.scoreoid.net | www.scoreoid.com

	import flash.display.MovieClip;
	import flash.net.URLVariables;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLLoader;
	import flash.events.Event;

	public class Main extends MovieClip
		private var url:String = "https://www.scoreoid.com/api/getGameField";
		private var request:URLRequest;
		private var requestVars:URLVariables;

		private var apiKey:String = "enter your API-key";
		private var gameId:String = "enter your game-ID";
		private var responseType:String = "XML";

		private var ulGetScore:URLLoader = new URLLoader();
		private var ulSendScore:URLLoader = new URLLoader();

		public function Main()
			Send a score to Scoreoid containing the name of the user and his or hers score */
			sendScore("Player name", "player score e.g 8278");	

			Show the score on stage

The sendScore function

This simple function recieves two values passed in as strings: user and score.

We start by pointing the url variable to the appropiate API-call, in this case the one called “createScore” and continue by packing a request handler with data.

The data is contained by an URLVariable we call requestVars which stores the fundamental elements needed to talk to Scoreoid (API-key / game-ID etc…)

Before sending the request we make sure to pass in the two crucial variables needed (score and user, both strings).

		private function sendScore(user:String, score:String):void
			url = "https://www.scoreoid.com/api/createScore";
			request = new URLRequest(url);
			requestVars = new URLVariables();
			request.data = requestVars;
			requestVars.api_key = apiKey;
			requestVars.game_id = gameId;
			requestVars.response = responseType;

			/* send score variables: */
			requestVars.score = score;
			requestVars.username = user;

			request.method = URLRequestMethod.POST;
			ulSendScore.dataFormat = URLLoaderDataFormat.TEXT;
			ulSendScore.addEventListener(Event.COMPLETE, sendScoreCompleteHandler);

Listen for a respond

By casting the data send back from Scoreoid as xml we´re able to check against a string “The score has been saved” to assure that the score we just send in fact got processed and saved by Scoreoid.

		//Send score complete handler:
		private function sendScoreCompleteHandler(e:Event):void
			//sending scores to scoreoid...
			var xml:XML = new XML(e.target.data);
			if (xml == "The score has been saved")
				trace("The score has been saved.")

Get scores – using it all

This function looks a lot like the sendScore function and would definitly need some cleanup considering the main difference lies in the url (getScores) and the score variables.

The get score variables:

Again, there´s plenty more to check out but to receive the 4 highest scores we use “limit” to limit the result, “order_by” to order the result by score values (“name” would give you a list ordered in alphabetical order) and lastly “dsc” to get the highest score first.

		private function getScores():void
			url = "https://www.scoreoid.com/api/getScores";
			request = new URLRequest(url);
			requestVars = new URLVariables();
			request.data = requestVars;
			requestVars.api_key = apiKey;
			requestVars.game_id = gameId;
			requestVars.response = responseType;

			/* get score variables: */
			requestVars.limit = 4;
			requestVars.order_by = "score";
			requestVars.order = "dsc";

			request.method = URLRequestMethod.POST;
			ulGetScore.dataFormat = URLLoaderDataFormat.TEXT;
			ulGetScore.addEventListener(Event.COMPLETE, getScoreCompleteHandler);


Putting it out there!

Inside our handler we cast the Scoreoid respond once again as xml and loop through each player object to put a movieclip on stage.

The movieclip we´re using lies inside the Flash IDE library exported for actionscript with the linkage name “PlayerResult”.


Contains two dynamic textfields: “name_t” for names and “score_t” for scores.

Scoreoid values:

To show something in our textfields we use “player.@username” and “player.score.@score”.

		//Get score complete handler:
		private function getScoreCompleteHandler(e:Event):void
			var scoreXML:XML = new XML(e.target.data);
			var playerResult:MovieClip;
			var pX:Number = 86;
			var pY:Number = 116;

			for each (var player:Object in scoreXML.player)
				//show results on stage:
				playerResult = new PlayerResult();
				playerResult.x = pX;
				playerResult.y = pY;

				playerResult.name_t.text = player.@username;
				playerResult.score_t.text = player.score.@score;


				pY += playerResult.height -1;



That´s all there is to it really, again you could propably optimize this to half the size but that´s not really the point here.

This is the end result btw:

So download the fla if you want and get your ass over to www.scoreoid.net!


Fretris device gameplay

Posted on: August 17th, 2011

Fretris gameplay on my Samsung Galaxy S running a high framerate.

Sorry for the blurriness!

SiON – mobile fail…

Posted on: August 15th, 2011

So as I wrote last week I looked into the cool sound framework SiON, hoping that it would work as a sound engine on mobile games

What flash genius Terry Patton predicted was true, the framework – though small in size, is a huge burden on a mobile processor…

Anyway I recommend to check it out at SiON Spark

Flash on! – Nicolas

SiON Sound AS3 – example 1

Posted on: August 5th, 2011

I´ve been playing around a bit with the excellent sound framework made by Kei Mesuda called SiON

This example uses SiON in its simplest way, playing two jazzy chords when the user clicks the stage

Get the swc / source:

To get started you need to head over to SiON Spark

Example 1 – Jazz SiON non standard voice:

Click stage for sound:

// Sample for event trigger
	import flash.display.*;
	import flash.events.*;
	import org.si.sion.*;
	import org.si.sion.SiONData;
	import org.si.sion.SiONVoice;
	import org.si.sion.utils.SiONPresetVoice;

	public class Sion extends Sprite
		public var composer:SiONDriver = new SiONDriver();
		public var melody:SiONData;
		public var presets:SiONPresetVoice;
		public var voice:SiONVoice;

		private var _on:Boolean = false;

		function Sion()
			stage.addEventListener(MouseEvent.CLICK, playSound);

		private function playSound(e:MouseEvent):void
			var sheet:String;

			if (! _on)
				sheet = "t100;";
				sheet +=  "%3@8 [b+2]1;";
				sheet +=  "%3@8 [f+2]1;";
				sheet +=  "%3@8 [c+2]1;";
				sheet +=  "%3@8 [g2]1;";
				sheet +=  "%3@8 [o2a2]1;";
				sheet = "t100;";
				sheet +=  "%3@8 t100 [b2]1;";
				sheet +=  "%3@8 [e2]1;";
				sheet +=  "%3@8 [c+2]1;";
				sheet +=  "%3@8 [f+2]1;";
				sheet +=  "%3@8 [o3d2]1;";

			presets = new SiONPresetVoice();;
			voice = presets['valsound.bells2'];

			melody = composer.compile(sheet);

			composer.sequenceOn(melody, voice, 0, 0, 1, 1);

			_on = ! _on;

/ Nicolas

AS3 Custom anti-alias

Posted on: December 13th, 2010

Ever wanted to change the thickness and sharpness settings through actionscript but didn´t know how?

Flash IDE:

To edit these settings within Flash you just need to click on your textfield and choose “Custom anti-alias” in the Anti-alias dropdown:

The actionscript way:

Doing the same thing in code requires a few steps and it can get a bit repetative, writing a class to handle stuff like this is maybe a good idea, anyway:

	import flash.display.Sprite;
	import flash.text.AntiAliasType;
	import flash.text.Font;
	import flash.text.GridFitType;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class CustomAntiAliasExample extends Sprite
		private var _t_format	:TextFormat = new TextFormat();
		private var _tf			:TextField = new TextField();
		private var _customFont	:Font = new ProjectFont();

		public function CustomAntiAliasExample()
			t_format.font 			= _customFont.fontName;
			t_format.size 			= 15;
			t_format.color 			= 0x000000;
			t_format.bold 			= true;

			// -------------------------------------> ANTI ALIAS PART:

			_tf.gridFitType 		= GridFitType.SUBPIXEL;
			_tf.antiAliasType 		= AntiAliasType.ADVANCED;

			// thickness:
			_tf.thickness 			= 50;
			// sharpness:
			_tf.sharpness 			= -200;

			// -------------------------------------------------------

			_tf.embedFonts 			= true;
			_tf.defaultTextFormat 	= t_format;
			_tf.text = "Hello World";


/ Nicolas