Learning AS3 from Books, freely…

I just realized how much free content we can get from Google Books. If you don’t have enough money to buy all the books about ActionScript 3.0, why don’t you just read them online?
Make a search for ActionScript 3 on Google Books and you will find some incredible title (not complete but still enough to start).

Here are some books you can start reading right now freely:
Essential ActionScript 3.0
ActionScript 3.0 Cookbook
ActionScript 3.0 Design Pattern
Flash CS3: The Missing Manual

Enjoy your readin :=)


Using URLVariables()

URLVariables Class allow you to send or receive data from an URL encoded feed (with the data property of the URLRequest class).
There is so two possible use:

  1. Sending parameters to a server side script
  2. Read parameters written from a server side script

The use is quite simple, let’s start by building the PHP file that will receive the variables from a POST method and echo them again with a list of parameters association by name and value: email=”..”&id=”..”&db=”…”.

< ?php

 echo "email=".$psPreRegEmail;
 echo "&id=".$FRM_ID;
 echo "&db=".$psBD;

Now we need to prepare our AS3 script that will send this 3 variables to our PHP file:

var request:URLRequest = new URLRequest("http://www.server.com/varsTest.php");
var variables:URLVariables = new URLVariables();//create a variable container
variables.sEml = email;
variables.sID = theForum;
variables.sBD = theDB;
request.data = variables;//add the data to our containers
request.method = URLRequestMethod.POST;//select the method as post
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.load(request);//send the request with URLLoader()

Here we send the variables and wait for the Event.COMPLETE, it will indicates us that the php files is totally downloaded (and so all the scripts has been executed). Now we can prepare our HandleComplete function:

function handleComplete(event:Event)
var loader:URLLoader = URLLoader(event.target);
var vars:URLVariables = new URLVariables(loader.data);
//Access data from the PHP file
trace("vars.email: "+vars.email);
trace("vars.id: "+vars.id);
trace("vars.db: "+vars.db);

That’s all!


JSON and AS3 URLRequest Class

A while ago, the as3corelib has been published on Google Code with a useful tool: JSON encoder and decoder.

JSON (JavaScript Object Notation) is a lightweight computer data interchange format (that is intended to solve XML structure weight), that allows you to send Object (Array, Strings, Number, …) to your server scripts or to JavaScript.

JSON is commonly used by Yahoo Web Services for example.

To use JSON and URLRequest even faster and simpler, I’ve create a small class that allows you to configure your URLRequest in one line (called PhpInteract), to add variables and to precise if your variables are encoded in JSON.

AS3 example to load a XHTML file:

var mi:PhpInteract = new PhpInteract(); //New object of the PhpInteract Class

Now to get the content of the file just do as usual with the onComplete Listener:

mi.addEventListener(Event.COMPLETE, completeHandler);

public function completeHandler(e:Event):void
		//file is completely loaded
		trace("File Content :n"+mi.content);

You are certainly thinking that a new Class to do this is completely useless… And I agree. Now we can do something more interesting and pass variables (encoded in JSON) to our server side script:

var arr:Array = new Array("a", "b", "c");//An array for the demo...
mi.loadFile("http://yourserver/fromFlash.php",arr, true);
mi.isJSON = true; //We specify that the content must be JSON encoded

Now for the demo, our below PHP code will decode the received JSON string and will re-encode it in JSON and echo it. Our Flash / Flex / AIR application will be able to decode the content as well and handle complex data from PHP (or any server side languages that can encode and decode JSON).

< ?php
$flash = $_POST['fromFlash'];

$testArray = json_decode($flash);

//We can access to the Array Element
echo "Array [0]".$testArray[0]."n";
echo "Array [1]".$testArray[1]."n";
echo "Array [2]".$testArray[2]."n";

echo json_encode($testArray);

What you need to make it work:
The as3corelib
The PhpInteract Class

Below is a complete sample:

	import flash.display.Sprite;
	import ch.metah.mURL.PhpInteract;
	import flash.events.*;

	public class InitmURL extends Sprite
		var mi:PhpInteract = new PhpInteract();
		public function InitmURL()
			//var arr:Array = new Array("a", "b", "c");//for the demo
			//mi.loadFile("http://metah.ch/seo/fromFlash.php",arr, true);
			//mi.isJSON = true; //is JSON content in loaded file?


			//USE EventListener
			mi.addEventListener(Event.COMPLETE, completeHandler);
			mi.addEventListener(Event.OPEN, openHandler);
			mi.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			mi.addEventListener(HTTPStatusEvent.HTTP_STATUS, HTTPHandler);
			mi.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);

		public function completeHandler(e:Event):void
			//file is completely loaded
			trace("File Content :n"+mi.content);
		public function openHandler(e:Event):void
			//trace("Download started");
		public function progressHandler(e:ProgressEvent):void
			//Handle Progress
		public function HTTPHandler(e:HTTPStatusEvent):void
			//trace("HTTP Status:"+mi.httpStatus);
		public function errorHandler(e:SecurityErrorEvent):void
			//Handle Security Error Here



W3C working draft: Use HTML(5) not Flash or Silverlight

Just read this news from Tim Anderson’s blog,
it appear that the W3C working draft has a statement about the use of proprietary UI languages.

As an open, vender-neutral language, HTML provides for a solution to the same problems without the risk of vendor lock-in.


For sophisticated cross-platform applications, there already exist several proprietary solutions (such as Mozilla’s XUL, Adobe’s Flash, or Microsoft’s Silverlight). These solutions are evolving faster than any standards process could follow, and the requirements are evolving even faster. These systems are also significantly more complicated to specify, and are orders of magnitude more difficult to achieve interoperability with, than the solutions described in this document. Platform-specific solutions for such sophisticated applications (for example the MacOS X Core APIs) are even further ahead.

Read the W3C working draft for HTML5

Even if HTML5 seems to be heading in the right direction:

  • New Structure
  • Block semantic elements
  • Inline semantic elements
  • Embedded media
  • Interactivity

The only point where I see an overlap with Flash or Silverlight technologies is for ‘Embedded Media’ and ‘Interactivity’.
However those are just a minor part of what is feasible with Flash…

So no, for me HTML5 is not going to make me stop using Flash & Flex, for Silverlight it’s another question as I didn’t even started using it…

For the semantic part, well I’m looking forward to use those new HTML5 elements, but seems that I’ll have to wait a long time :(


FITC is coming to Europe – Amsterdam – February 2008

Not sure everybody knows about it (???), sure enough I’ll be heading there!

FITC Amsterdam 2008

Having successfully held events in Toronto, Chicago, Winnipeg, and Hollywood, FITC makes its Europe debut in Amsterdam.

Explore the creation of NEW ideas and concepts, where the limits of technology in design and art can be experimented with, explored, broken and reinvented. Learn how designers and technologist are pushing limits that go beyond what their tools are designed to do, how they find alternate ways to get what they want, and push the boundaries of what is possible to avoid mediocrity.

From its historic museums and world-renowned artists to its well known liberal attitudes, everything about Amsterdam is eclectic, fascinating and exciting. FITC is proud to bring its unique brand of event to this diverse and inspiring location.

FITC comes to Amsterdam to facilitate the interaction of some of the most talented design work with the best technologists found today, laying the groundwork for the future in which digital interactive interfaces surround us. Whether your weapon of choice is Flash, Photoshop, Illustrator, After-Effects, or a combination of all, you’re in for a wild ride of presentations, panel discussions, and of course the infamous FITC parties. With some of the most interesting and engaging presenters from around the world, its 2 days and nights that will leave you inspired, energized and awed.

For those of you who are new to the festival, FITC is now entering its 7th year, and is the only festival of its kind; combining cutting edge technical and creative speakers from around the world.