Monthly Archives: January 2008

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 :=)

Ahmet

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
 $psPreRegEmail=$_POST['sEml'];
 $FRM_ID=$_POST['sID'];
 $psBD=$_POST['sBD'];

 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!

Ahmet

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
mi.loadFile("http://www.w3.org/TR/2008/WD-xhtml-access-20080107/");

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:

package
{
	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?

			mi.loadFile("http://www.w3.org/TR/2008/WD-xhtml-access-20080107/");

			//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
			//trace("Loaded"+mi.bytesLoaded+"Total"+mi.totalBytes);
		}
		public function HTTPHandler(e:HTTPStatusEvent):void
		{
			//trace("HTTP Status:"+mi.httpStatus);
		}
		public function errorHandler(e:SecurityErrorEvent):void
		{
			//Handle Security Error Here
		}

	}
}

Ahmet

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.

BUT:

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 :(

Ahmet

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.

Ahmet

The End of SWF-SEO nightmare? Google indexing SWF with Adobe SDK?

I came across this news from the Los Angeles Flex Users Group, then I followed to the new O’Reilly website on RIA: “Inside RIA” to finally end up on John Dowdell’s blog.
As it is the first time I disagree with John, and my answer started to be long, I preferred to import it here directly:

IMHO, Google indexing SWF text would be in fact a great news. I already saw some SWF content indexed by Google SE (mostly it was from static Flash Paper SWF).

The fact that we don’t promote our site only by pushing a keyword is obvious, but denigrating the absolute needs for SWF to be readable from SE is somewhat very strange.

As John said optimizing HTML, links inbounds and Metadata (not sure Metadata are still of any needs from Google) are important but where do you make the difference between HTML and SWF (from a not technical point of view)?
The major problem with SWF is mostly that they are providing dynamic content. The second major problem would be that the text can be converted to vector (so very hard to understand by computer, just see how captcha works…).

Those two problems take apart, why couldn’t we tag our SWF text with HTML tags? Can’t I tell to Google that this part of text is a H1 title or any HTML tag available? Or at least couldn’t I just be knowing how will Search Engines index my content?
A long time ago, I used the text under SWF layer solution to help increase the readability of important content to Search Engines, based on the already known behavior of search engines with HTML.

The sentence that made me jump down my chair was: “it’s hard to see how it would matter much“.
Well, for me just knowing that Google is interested in understanding SWF content is a great news! And I really hope that Matt info was solid :=)

Ahmet

AIR Application Visible from the Browser: the Browser API

As you certainly already know, the Adobe AIR beta 3 is out since mid December. I’ve just read on Oliver Goldman’s blog about a very interesting API added to AIR:

The ability to detect and launch AIR-based applications from within the browser, this API lets you do the following from within the browser:

  1. Install an AIR-based application
  2. Detect if an AIR-based application is installed, and
  3. Launch an (installed) AIR-based application.

Now that is great, so we can prompt someone to download our AIR application if he hasn’t previously installed it and else we can launch the application. So if you have one application that works for several website you can allow them to use it…
I need to find some free times to see if we can also transfer some args. to the applications from the browser to the applications (from www.a.com to AIRapps.exe).

Despite all the security issue that run along the Badge installation of AIR applications I think it is really a nice move and a great improvement. I already know that I won’t have time before February but after this date you can expect some tutorials on AIR very soon :)