Flex sdk 3.5.0 problem with ternary operators

I’ve got problems to isolate the problem into a very big project with many linked sources. After hours inspecting and commenting lines of code trying to figure out the reason why flex gave me an “internal error” I found the problem.
This very simple script was crashing the flex compiler if using the 3.5.0 sdk ( revision ).
Fortunately the 4.0.0 compiler works fine. At the end it seems to be the combination of “+” and “-” and the ternary operator.
   import flash.display.Sprite;
   public class ternary_test extends Sprite
      public function ternary_test()
         var n: Number = 0;
         var d: int = 3;
         var k: int = 5;
         var j: int = 10;
         n = 1 + ( -( d == 0 ? k : j ) );
         trace( "n=" + n );

will cause the compiler to crash with the following stack trace:


    [mxmlc] Loading configuration file /Applications/Adobe Flash Builder 4 Plug-in/sdks/3.5.0/frameworks/flex-config.xml

    [mxmlc] Error: null

    [mxmlc] java.lang.NullPointerException

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:1290)

    [mxmlc] 	at macromedia.asc.parser.UnaryExpressionNode.evaluate(UnaryExpressionNode.java:51)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:2153)

    [mxmlc] 	at macromedia.asc.parser.ListNode.evaluate(ListNode.java:44)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:1497)

    [mxmlc] 	at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:56)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:2124)

    [mxmlc] 	at macromedia.asc.parser.ArgumentListNode.evaluate(ArgumentListNode.java:45)...

Flex 3 Tree double-click to edit

Some people asked about changing the default editing behavior of a Flex 3 Tree control so  that item editing starts on a double-click event instead of the default single click.

Indeed it has been covered several times on forums or mailing list, but it’s faster to create a simple script than search for it sometimes.

Here’s the files:
Here’s the live demo:

Flash camp on the beach (Rimini)

The new Flash camp will be in Italy, Rimini, and will take place on 5th of September. Participation is free!

Order your ticket via eventbrite.
The meeting will take place at Hotel Sporting Viale Vespucci, 20 47900 Rimini (Italy).
As a camp everybody can join us as a speaker, today we have a great group of speakers already confirmed:
  • Jaco Pixeldump (www.pixeldump.org)
  • John Lindquist (http://pv3d.org, http://flex4.org)
  • Joost Nuijten
  • Eros Marcon (actionscript.it)
  • Simon Slooten (www.simonslooten.com)
  • Matteo Lanzi (aka Gallo_Teo flex-developers.org)
  • Adam Flater
  • Michael Labriola (http://blogs.digitalprimates.net/codeSlinger/)
  • Rich Tretola (http://blog.everythingflex.com)
  • Gabriele Farina (www.sephiroth.it)
  • Alessandro Crugnola (www.sephiroth.it)
  • Michael Plank (www.powerflasher.de)
  • Rich Tretola
  • Matt Chotin
  • Giorgio Natili (flex-developers.org)
What’s New in Flex 4 (Matt Chotin) 9:00 – 9:45
Most of us have heard that the Flash Platform tools are getting a major upgrade with Flex 4.  We’ll give a high-level overview of what’s coming in the three major components: Flash Catalyst, Flash Builder, and the Flex Framework.
Concepting Rich Internet Applications (Joost Nuijten) 9:50 – 10:35
The pitfall of Flex applications is to thrown in a bunch of buttons of fields, the Flex skin looks nice, and the say: “There we have another Rich Internet Application”. To my opinion it is much more than that. It’s about creating the ultimate user experience by mixing interaction design, emotion and common sense.
“One key element of a good ergonomic web application, or at least a sign that it works ergonomically, is that you want to stay there — like a big old comfortable chair that wraps you up and you just don’t want to leave it, ever… (well, at least, maybe, for a little while more…)”
(SyMetric Sciences, Inc., 1999)
Flex 4 in 3D: The UI of the Future is Now! (John Lindquist) 10:40 – 11:25
Ok, the title might be a bit over-the-top, but the new 3D features of Flash Player 10 do allow us to pull off some pretty cool tricks. This session will cover step-by-step how to take advantage of the the 3D api. We’ll start by creating our own custom and reusable 3D layouts and work our way to creating 3D components. Once we’ve brought everything together into a full 3D application, we’ll end with a  discussion of the advantages and disadvantages of using 3D in user interfaces.
TESTING WITH FLEX AND FLASH BUILDER (Michael Labriola) 11:30 – 12:15
Unit testing in Flex is taking a giant leap forward. First learn about the latest technologies, their integration into the Flex developers workflow and the promises offered by these advancements. Then learn how to write tests using these new methods, how those tests can be used effectively and the theory behind their use. Finally, learn about the extension points and how numerous testing projects can now converge to offer solutions now and into the future of Flex.
FDT – Pure Coding Comfort (Michael Plank) 12:20 – 13:00
You want to improve your ActionScript/Flex development workflow and boost your programming
efficiency? Michael demonstrates how the coding flow completely changes with FDT by using
features like Quick Fixes and Auto Completion. FDT is an Eclipse based IDE for ActionScript
and MXML development that provides pure coding comfort.
Not only professionals prefer working with FDT, the tool is also appropriate for beginners
because of supporting features like e. g. live error highlighting. A short speed coding example
on stage illustrates how fast the coding workflow can be with FDT.
Mate – The beauty of a simple framework (Simon Slooten) 13:30 – 14:15
Mate is a Flex framework that is simple, elegant, scalable and simply beautiful. In this session you will get an introduction to Mate, as well as look at a Flex Application that uses Mate
ByteArray:  extend your swf apps with extra features (Marco Fusetti aka Jaco) 14:20 – 15:05
ByteArray is a great flash player feature that let you load/treat/save binary data.
Let’s look into some techniques and examples on adding features such swf black box, sound data, external swf inspection and more.
Using Merapi (Adam Flater) 15:10 – 15:55
An introduction to native hardware and software integration in Flash
Flex sdk (Matteo Lanzi aka Gallo Teo) 16:00 – 16:45
How to patch it to solve common architectural problems and improve performance
Flash Catalyst/Flash Builder 4 ˆ Designer/developer Workflow (Eros Marcon) 16:50 – 17:35
How to design and optimize an artwork for FC, importing design in FC, adding interaction, working with states and transitions, wiring FC interactive UI with real data in Flash Builder 4
Extending flash applications (Alessandro Crugnola aka Septhiroth and Gabriele Farina) 17:40 – 18:25
A quick walkthrough from static plugins to dynamic scripting
Java, Flex and Model View Presenter (Giorgio Natili) 18:30 – 19:05
Flex loves Java applications that expose API deployed under Blaze DS, follow us in a complete tour that shows the process to define good API for a Flex / Air application that follow Model View Presenter design pattern and get the key points of GUI Architectures for responsive applications.
Flex image uploading and manipulation via Pixel Bender (Rich Tretola) 19:10 – 19:40
Flash Player 10 introduced some new features including the ability to write a file to the users file system as well as the usage of Pixel Bender filters. In this session you will see how to upload an image within a Flex application,  filter the image with a Pixel Bender filter, and then use the JPEGEncoder class to encode the filter image to a ByteArray.

[Bindable]? No, thanks

Working on huge projects sometimes let you take long optimization sessions.
During one of these sessions I was trying to find a way to optimize a bunch of code which was taking too long time to process.
The big big bottleneck I discovered, and I didn’t know before (my fault), was the **[Bindable]** attribute of one of the classes included in the process.
This process was creating something like 1 million instances of this class during its life. After a first optimization in which I created an object pooling, thus reducing the total execution time from 16 seconds to 13, I found this incredible trick which reduced the total execution time to **1 second!!**

Let’s say you have a class like this:

package it.sepy.test

public class RGB
private var _blue: int;
private var _green: int;
private var _red: int;

public function RGB()

public function get blue(): int
return _blue;

public function set blue( v: int ): void
_blue = v;

public function get green(): int
return _green;

public function set green( v: int ): void
_green = v;

public function get red(): int
return _red;

public function set red( v: int ): void
_red = v;

and a simple script which create 100000 instances of this class (my script wasn’t like this, but for simplicity I’m doing this example):

import flash.display.Sprite;
import flash.system.System;
import it.sepy.test.Pool;
import it.sepy.test.RGB;

public class test extends Sprite
public function test()

private function startTest(): void
var t1: Number = new Date().getTime();
for ( var i: int = 0; i < 100000; i++ ) { var rgb: RGB = new RGB(); rgb.red = i % 255; rgb.green = i % 255; rgb.blue = i % 255; } var t2: Number = new Date().getTime(); trace( 'total execution time:', ( t2 - t1 ), 'ms' ); trace( 'memory usage:', System.totalMemory / 1024, 'kb' ); } } }

now launch the script and in the output I have this result
total execution time: 2381 ms
memory usage: 5924 kb

NOW. Remove the **[Bindable]** property from the RGB class and launch again the test script. See at the output console and the new results are:
total execution time: 236 ms
memory usage: 2720 kb

So, I know that bindable were not created for this kind of jobs, but if using it make 10 time slower my scripts, then I don't see any valid reason to use it anywhere.

Multiple objects using Senocular TransformTool

Senocular TransformTool is one of the best and most used components around the net. It is really useful for those (include me) who don’t want to fight against Matrix, concatenation of Matrix and all those painful stuff…

The only ‘lack’ of that component is that it does not support multiple objects as target. If you want to transform n array of elements at the same time you should have all those elements in the same parent DisplayObjectContainer and then set that parent as target of TransformTool.

But maybe sometimes this is not possible due to various reason and you want to use different items with different parents as dataprovider.

This is the solution I actually use for that particular situation (Remember that I’m using a modified version of the TransformTool)

This is the final result: ( Ctrl+click on the tree leaves to multiple selection )

Live Demo of the Trasform Tool using multiple objects

( Here you can download download the source files ).

In few words the solution I found is this:

Create a temporary layer which will be the TransformTool target.
For every item in the selection Array create a temporary shape with the size of the getBounds() of the real object. Store this shape into the temporary layer, assigning to it the concatenated matrix of the real object.

Once there’s a transformation of the temporary layer get every shape transform matrix and assign back to the original object.

Probably there are many and better solutions to do the same, this is just the one I found, maybe someone has better approach to this problem (and he is welcome here!)

Java 6 Update 10 breaks Flex compiler!

I just want to share this problem I found so maybe someone can save some time..

Today while surfing the net I received a notification of an update of my Java installation to the Update 10 in order to see correctly the contents of that site.. bla bla bla..

Sometime later I switched to Flex and at the first execution of my ant script for compiling a flex project I suddenly received this beautiful error:
[exec] Error: java/security/MessageDigest
[exec] java.lang.NoClassDefFoundError: java/security/MessageDigest
[exec] at java.io.ObjectStreamClass.computeDefaultSUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.access$100(Unknown Source)
[exec] at java.io.ObjectStreamClass$1.run(Unknown Source)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.io.ObjectStreamClass.getSerialVersionUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject0(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject(Unknown Source)
[exec] at flex.util.SerializedTemplateFactory.load(SerializedTemplateFactory.java:30)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:162)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:151)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:137)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.generateSupportCode(GenerativeSecondPassEvaluator.java:256)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.modifySyntaxTree(GenerativeSecondPassEvaluator.java:355)
[exec] at flex2.compiler.as3.binding.BindableSecondPassEvaluator.evaluate(BindableSecondPassEvaluator.java:102)
[exec] at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:106)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:338)
[exec] at macromedia.asc.parser.StatementListNode.evaluate(StatementListNode.java:60)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:923)
[exec] at macromedia.asc.parser.ProgramNode.evaluate(ProgramNode.java:80)
[exec] at flex2.compiler.as3.genext.GenerativeExtension.parse2(GenerativeExtension.java:114)
[exec] at flex2.compiler.as3.Compiler.parse2(Compiler.java:386)
[exec] at flex2.compiler.API.parse2(API.java:2390)
[exec] at flex2.compiler.API.parse2(API.java:2348)
[exec] at flex2.compiler.API.batch2(API.java:375)
[exec] at flex2.compiler.API.batch(API.java:1117)
[exec] at flex2.compiler.API.compile(API.java:1290)
[exec] at flex2.compiler.API.compile(API.java:1210)
[exec] at flex2.tools.Compc.compc(Compc.java:158)
[exec] at flex2.tools.Compc.main(Compc.java:41)

so I tried also to compile another project before go crazy, but I got this another java funny error, which was more or less unreadable as the previous one!

Fortunately I remembered the update I did of Java! And in fact after remove that update everything worked again!

Flex Builder on Ubuntu Hardy 8

UbuntuI don’t know exactly why, but the first time I found the link of an article about the first Ubuntu 8 hardy alpha release I couldn’t wait anymore and so I immediately upgraded my distribution..
I can’t resist to alphas and betas! damn!

Anyway, a part the obvious problems related to an alpha version, such as video card, mouse etc.. the most frustrating thing was the fact my eclipse installation was corrupted.. I reinstalled eclipse again and downloaded again flex builder for linux.
But when trying to install Flex builder  I received a really nonsense java exception error, which more or less was:

xcb_xlib_unlock: Assertion `c->xlib.lock’ failed

After some google searches I found out the solution for my problems ( I’m posting here in case someone else is so crazy to upgrade his ubuntu version with a flex builder installed into ):

In a terminal window:
sudo sed -i 's/XINERAMA/FAKEEXTN/g' /usr/lib/jvm/java-6-sun-
Then restarting flex builder bin installation everything worked again and now I’m happy with my flex builder linux version again 🙂