I’ve been writing ActionScript for nigh on 10 years; but I’ve always used separate text editors like TextMate to write the code and used the Flash IDE to compile it. I decided that this weekend I’d give Flash Builder a try, since it’s clearly the way forward.
Anyway. I’m using Flash Builder 4.6 on OSX — installed this morning and I haven’t futzed with it — and I built a simple “Actionscript Mobile App” (because my current project at work is a mobile air app, being built with the Flash IDE).
package
{
import zakariya.layout.RootLayoutSprite;
public class DoesThisEvenWork extends RootLayoutSprite
{
public function DoesThisEvenWork()
{
super();
trace( "hello... what's my size: " + this.size );
}
}
override public function onLayoutUpdated():void
{
super.onLayoutUpdated();
}
override public function onSizeChanged():void
{
super.onSizeChanged();
trace( 'onSizeChanged..., new size: ' + this.size );
}
}
The class RootLayoutSprite derives from LayoutSprite and is part of a layout management API I wrote and have used in dozens of projects, big and small. The onLayoutUpdated and onSizeChanged methods are defined in LayoutSprite, as well as the size property.
The definition looks more or less like so:
package zakariya.layout
{
public class LayoutSprite extends Sprite {
/*
Called after this Sprite's size changes, before layout of children is executed
*/
public function onSizeChanged():void
{}
/*
Called after this Sprite's size changes, after layout of children is executed
*/
public function onLayoutUpdated():void
{}
}
}
The zakariya.layout code is raw code in a local repo — not compiled to SWC — and it’s all in a folder structure which I added to the project’s source path. Flash builder clearly recognizes the base classes because it recognizes RootLayoutSprite.
When I try to build this I get the following:
1006: A super expression can be used only inside class instance methods. DoesThisEvenWork.as /DoesThisEvenWork/src line 17 Flex Problem
1010: The override attribute may be used only on class property definitions. DoesThisEvenWork.as /DoesThisEvenWork/src line 15 Flex Problem
1010: The override attribute may be used only on class property definitions. DoesThisEvenWork.as /DoesThisEvenWork/src line 21 Flex Problem
1020: Method marked override must override another method. DoesThisEvenWork.as /DoesThisEvenWork/src line 15 Flex Problem
1020: Method marked override must override another method. DoesThisEvenWork.as /DoesThisEvenWork/src line 21 Flex Problem
So, Flash Builder will not let me override those methods. If I take away the ‘override’ attributes, Flash Builder complains that the methods are defined in a base class. Facepalm.
Mind you, this simple code works fine in the Flash IDE.
I honestly have no idea what’s going on. I haven’t fooled with the Flash Builder config. I’ve avoided Flash Builder for years because I didn’t write Flex projects… and in my free time I write C++ so I don’t know anything about the Flash Builder eclipse toolchain.
My assumption is that the Flash IDE has a less strict compiler than Flash Builder, and as such, I’ve been doing something wrong for so long I didn’t know it was wrong.
Help?!
The code should not compile in the Flash IDE either – it contains a syntax error.
You closed the class declaration after the constructor. Just move that curly brace all the way down and everything should work fine.