Use Away 3D man …

… or at least give it a try!

Working on Aviary I had the plesure to meet Alexander and Fabrice, the creator and one of the actual maintainers of Away 3D engine.

As you might known, we are using Away 3D for Hummingbird, and I had the plesure (yes, another :P) to give a look at the code an work in touch with the developers. I have to admit that Away 3D is really good!

I’m far to be the best person to suggest one framework over the others, but what I can do is tell you why I think Away 3D is (at least) worth a try, even if you are already working with Papervision 3D or the other engines. The first thing to know is that both the projects comes from the same branch – they have been splitted a few years ago (maybe just an year but I’m not sure) and then they followed two different paths. During my quick and basic experience with Away 3D I see that it has a real clean and powerful API (you have animation for instance or really good materials), good documentation and tutorials (see Fabrice‘s blog for a bunch of them!), more precise a quick rendering. And part of the new Papervision 3D 2.0 code is inspired by that library.

The various libraries outta there are for different purposes, and probably are taking (or will take) different directions (ie: see Alternativa 3D for instance, which seems well suited for games). But trying many of them instead focusing only on the most famous one is a really good thing – many users comes from PV3D for instance and are really happy about Away!

Don’t take my assumptions as gold: this is what I think after just a bit of playing 😉

AS3 tour, last stop Milan

Just come back from the big Apple and discovered that Adobe as3tour, presented by Colin Moock, will be in Italy on Moday 23rd of June, and more precisely in Milan at the Atathotel Executive.

Also, this will be the last stop of the tour! So don’t miss it if you live near Milan, like me!

The course teaches object-oriented programming fundamentals in
ActionScript 3.0. it is designed for Flash users with beginner to
intermediate programming skills (*NOT* advanced programmers). the target
audience should have:
* familarity with the Flash authoring tool
* basic knowledge of variables and functions
* little or no experience with object oriented programming

topics covered include object-oriented programming, classes, objects,
variables, methods, packages, event handling, displaying things on
screen, and compiling and running programs.

Anyway, dont miss the beer(s) at the end of the meeting!! 🙂

Talking about dead projects…

Today I was watching some of the pictures from the last Flex 360 meeting in Milan ( on 7/9 April ) which someone posted on Flickr you can’t imagine my surprise when I saw this photo.

Unfortunately I dont know what they were talking about in the meantime, but for me just watching that picture gave me a sense of melancholy!

But… I don’t think the only advantage of SEPY was the “easy to use”, for what I remember it had tons of useful features..

By the way, are you sure that is a dead project?  🙂

Top Down or Bottom Up for Expression Evaluation ?

Last time I wrote about Top Down parsing, a technique for parsing that can be easilly implemented manually using function recursion.

Today it is time to talk about one of the other ways of parsing, called Bottom Up parsing. This technique try to find the most important units first and then, based on a language grammar and a set of rules, try to infer higher order structures starting from them. Bottom Up parsers are the common output of Parser Generators (you can find a good comparison of parser generators here) as they are easier to generate automatically then recursive parser because they can be implemented using sets of tables and simple state based machines.

Writing down manually a bottom up parser is quite a tedious task and require quite a lot of time; moreover, this kind of parsers are difficult to maintain and are usually not really expandable or portable. This is why for my tests I decided to port bYacc (a parser generator that usually generates C code) and edit it so it generates ActionScript code starting from Yacc-compatible input grammars. Having this kind of tool makes things a lot easier, because maintaining a grammar (that usually is composed by a few lines) is less time expensive than working with the generated code (that usually is many lines long).
I will not release today the port because actually I had not time to make sure it is bugfree and I’ve only a working version for Mac, but I plan to release it shortly if you will ever need it for your own tasks. My goal for today was to compare the speed of the parser I wrote with an automatically generated bottom up parser, to see which is the faster approach.

I created a bottom up parser which is able to execute the same expressions accepted by the expression evaluator I wrote last time. There are anyways some differences that – as you will probably and hopefully understand in the future – that make those parsers really different. Some will be disussed shortly here.

To do that I created a Yacc grammar and some support classes.
The parser grammar is really simple and really readable:
%{
%}
%token NUMBER SYMBOL
%left '+' '-'
%left '*' '/'
%left NEG
%%
program
: expr { Vars.result = $1; }
;
expr
: expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; }
| expr '/' expr { $$ = $1 / $3; }
| '-' expr %prec NEG { $$ = -$2; }
| '(' expr ')' { $$ = $2; }
| SYMBOL '(' expr ')' {
if( Vars.SYMBOL_TABLE[ $1 ] )
{
$$ = Vars.SYMBOL_TABLE[ $1 ]( $3 );
} else
{
trace( "can't find function" );
}
}
| SYMBOL {
if( Vars.SYMBOL_TABLE[ $1 ] )
{
$$ = Vars.SYMBOL_TABLE[ $1 ];
} else
{
trace( "can't find symbol" );
}
}
| NUMBER { $$ = yyval; }
;
%%

Continue reading the extended entry to see the results. Continue reading

Flash Switcher for Windows, OSX and Linux

With the upcoming release of Firefox 3 I thought I had to verify my extensions to see if they work with the new Firefox version too.
For the first version of flash switcher I did two different extensions for Windows and Mac. That was a problem for maintenance.

This time I wrote the extension from scratch and I decided to make it as much as cross platform as possible. Moreover I wanted to make the installation of new plugins easier than in the previous version of flash switcher extension ( where you had to copy manually the plugin file into the extension’s directory.. ).

Thus now this extension works ( at least with my tests and people who tested it ) with Windows, OSX and Linux. Specifically it has been tested on:

  • Windows XP
  • Ubuntu linux 8.04
  • OSX Leopard and Tiger

Also the installation of new plugins now it’s easy. Just click on the installed flash plugin and click “save”. Well, I think it’s quite easy 🙂

The only issue with the new extension is that it’s quite big because it comes with 2 flash versions for every OS platform. So it’s about 14Mb.

I also did a couple of video to show how it currently works on different platforms. Currently there are 2 videos (ubuntu and osx usage).

Flash switcher Ubuntu

In order to use this extension ( if you want to try it ) you need Firefox 3.
P.S. If you want to add more flash players to the extension, download and install the version you want from the flash player archive page.
Once a new flashplayer has been installed onto your system you can save it into your flash switcher archive using the “save as” menu item of the flash switcher.

Install flash switcher

Runtime expression evaluation in ActionScript

Finally I have a bit of free time to write down this post.
Some days ago a guy on the forum asked about how to evaluate at runtime simple mathematical expressions with support for symbols and function calls.

Now that the eval function have been removed from the language for reasons I’ve not enought time to talk about, we need to parse and execute those expressions manually.

I built a simple Actionscript library that can be used to parse mathematical expressions: it has support for function calls, for variables and it is able to convert the expression into a postfix rappresentation if you may need it. The expression parser is quite simple and have been built manually following some concepts related to programming language compilers; it includes a Scanner (or lexer – however you want to call it) to tokenize the expression, a Parser that convert the expression into an Abstract Syntax Tree and a simple routine that evaluates that AST using a Symbol Table as evaluation context.

There are no comments inside the code right now; I hope to find a little bit of time to write an in depth discussion about this topic. In the mean time you can continue reading the entry for a general explanation about how does the code works and for some examples that may be useful.

Here is a simple example that shows how does the code works:

import it.sephiroth.expr.CompiledExpression;
import it.sephiroth.expr.Parser;
import it.sephiroth.expr.Scanner;
public class Example
{
public static function run(): void
{
var expression: String = "sin( x / ( 8 / 2 + (-0.12 + 2.3) * x / x ) ) * 100";
var scanner: Scanner = new Scanner( expression );
var parser: Parser = new Parser( scanner );
var compiled: CompiledExpression = parser.parse();
var context: Object = {
x: 100,
sin: Math.sin,
cos: Math.cos
};
trace( 'Postfix:', compiled.toString() );
trace( 'Result:', compiled.execute( context ) );
}
}

Before I forgot, you can download the source code here with a simple example included.

Continue reading

Finally a code coverage tool for AS3!

Today is really a good day.

I was waiting for this kind of tool since a lot of time, and thanks to Joe we can finally do Code Coverage of our Actionscript code.

The project is hosted on Google Code, and can be obviously downloaded for free; the project is born after some tests of the author, that edited the Flex compiler to include additional informations that are used to generate a code coverage log that then can be read by softwares that display the output in a more user friendly and fashion way.

For anyone who doesn’t know, Code Coverage is a good practice used most in software testing, that is applied to understand how much source code is touched by our tests. This way a developer knows if a test covers all the source code (or the required portions) and can tune his tests if they don’t.

This project is probably one of the first born after the public release of the Flex SDK source code, and we are pretty sure that there are much more projects coming in the near future.

Finally we can do a little bit of Code Coverage in Aviary 🙂

cacheAsBitmap hell

Last week I spent a whole day trying to solve an issue in Phoenix due to a strange problem which comes up suddenly after some code changes.
The problem was that now using the transformation tool the bounds of the selected bitmap were not detected correctly and the tool itself didn’t work.
So I spent a lot of time in checking out all the recent code changes ( and they were a lot! ) to find out the possible cause…
Anyway, I was lucky to figure out the problem by accident and the problem was cacheAsBitmap!

The problem with the tool is because in order to find the correct bounds of any element on the stage it use the .concatenatedMatrix property of the element itself ( which represents the combined transformation matrixes of the display object and all of its parent objects, back to the root level ).
BUT if any of its parent display object ( not the root itself ) has the cacheAsBitmap property set to true then the concatenatedMatrix returns a wrong value!

I put a real simple flash example of what I mean. Just click on any of the 2 colored objects to activate the transform tool, then click on the “cache” button and click again on those objects to see the difference.

[kml_flashembed publishmethod=”static” fversion=”10.0.22″ movie=”http://blog.sephiroth.it/wp-content/uploads/2008/03/cacheasbitmap_hell.swf” width=”450″ height=”450″ targetclass=”flashmovie” bgColor=”#ffffcc”]

Get Adobe Flash player

[/kml_flashembed]

P.S. I’ve reported the bug in the flash player bugbase, if anyone is interested in watch or vote for it.