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 3.5.0.12683 ).
Fortunately the 4.0.0 compiler works fine. At the end it seems to be the combination of “+” and “-” and the ternary operator.
package
{
   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:

compile:

    [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)...

Alchemy installation problems under OSX

I’m writing this little issue I discovered today in the alchemy installation under OSX, in case someone else is having the same problem…

In fact, today I decided to makes a little swc library for an actionscript project using alchemy ( because of the lacks of union in flash ), so I downloaded the alchemy toolkit for OSX.


I spent a couple of hours trying to make it working on my Snow Leopard and because I’m not a shell and perl expert I finally moved to the linux toolkit under ubuntu ( even if on linux the Flex builder is really far to be usable!)
Anyway, this evening I decided to spend some more time trying to understand why when I was trying to execute the alchemy “gcc” script ( the ones inside the achacks folder, which is a perl script) nothing happened.
After long time with old style “print” debugging strategy, at the end I discovered an error in the “config” script in the main alchemy installation folder.
At this line (line 33):
if echo $MACHTYPE | grep darwin &> /dev/null; then
I had to modify it into:
if echo $MACHTYPE | grep -i darwin &> /dev/null; then
because the command “echo $MACHTYPE” outputs “x86_64-Apple-Darwin“, with the uppercase “D”.
In fact, after that modification everything finally worked!

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:

[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
{

[Bindable]
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):


package
{
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()
{
startTest();
}

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.

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-1.6.0.04/jre/lib/i386/xawt/libmawt.so
Then restarting flex builder bin installation everything worked again and now I’m happy with my flex builder linux version again 🙂

Releases: BlazeDS & Flex Builder 3 Beta 3

Today is a good day for announcements!
I’ve just read the Adobe plans to release, as opensource (LGPL 3?), on labs its Remoting and Messages technologies under the codename BlazeDS.
Moreover Adobe published AMF binary data protocol specifications ( the technology on which the BlazeDS remoting implementation is based).
The source code will be available for download in early 2008

Second announcement is the release on labs of Adobe Flex Builder 3 Beta 3 (M4). Cool, I’m working almost all the time with flex!.. but why only mac and pc downloads are available? The Linux version is still the alpha released on 12 October!

Actually I almost switched to ubuntu, moreover the fact that there is Flex Builder also for Linux allowed me to spend more and more time on my ubuntu partition and I really feel satisfied. Flex Builder for linux is more and more stable than all the other Flex betas for Windows or Mac ( even if the more I use eclipse and the more I hate it… ), so why give us only that candy?