Category Archives: Flash

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

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

ASTRA: ActionScript Toolkit for Rich Applications

I followed a link to ASTRA from Flashbookmarks.
Strangely I never heard about ASTRA althrough I already knew Yahoo! had a Flash developer center.

So what is ASTRA? Well,

ASTRAASTRA, the ActionScript Toolkit for Rich Applications, is Yahoo!’s collection of Flash and Flex components, libraries, toolkits and advanced applications. These libraries are open-source and available under the BSD license.

You will find some:

Flash CS3 Components Library:

  • Tree
  • Menu
  • TabBar
  • AutoComplete [Nice!]
  • Charts [Nice!]
  • Flash Kit:

    The Badge Kit is an XML-based framework for rapid development of small interactive Flash applications. You can learn how to use the Badge Kit very quickly, and most of the usage scenarios require no knowledge of Flash.

    So that is not so much for us…

    Web APIs Library

    Yahoo! AS3 API libraries are a set of wrapper tools that facilitate access to Yahoo!’s Web APIs from Flex and Flash. These libraries create an abstraction layer above the communication protocols used by Yahoo! servers, enabling Flash and Flex developers to send and retrieve data without any additional parsing. The AS3 libraries are easy to install and all accessible methods are fully documented. These libraries are open source and available under the BSD license.

    Libraries available by now:

  • Yahoo! Answers AS3 API
  • Yahoo! Weather AS3 API
  • Yahoo! Search AS3 API
  • Yahoo! Upcoming.org AS3 API
  • Yahoo! Maps AS3 Communication Kit
  • Interesting, isn’t it?

    Ahmet