-
Notifications
You must be signed in to change notification settings - Fork 261
Common Problems
Here’s a list of some commonly recurring problems that people face when getting started with Robotlegs.
The Flash/Flex compiler will strip out non-standard metadata unless you tell it not to – this includes the [Inject] and [PostConstruct] metadata that Robotlegs needs to function correctly. Sometimes, when building an AIR application for example, the metadata will stay intact while debugging but will be stripped out when you publish your release build. You need to tell the compiler that you want it to keep the [Inject] and [PostConstruct] metadata tags.
The Robotlegs SWC includes the required compiler arguments for you, but when linking against the source you will need to add the arguments yourself:
Right-click your project and click Properties. Go to “Flex Compiler”, and under “Additional compiler arguments” add:
-keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct
Select “Export SWC” in your publish settings. This will force the Flash compiler to keep all metadata intact.
Make sure to hang on to your context! We’ve seen a lot of people make this simple mistake. Consider the following (the WRONG way):
public class HelloActionScript extends Sprite { public function HelloActionScript() { var context:HelloContext = new HelloContext( this ); } }
The problem here is that the context is scoped as a local variable, and as such it will be free for Garbage Collection pretty much straight away. The context might function for a little while, but at some point in time it will be GC’d and cease to exist.
public class HelloActionScript extends Sprite { private var context:HelloContext; public function HelloActionScript() { context = new HelloContext( this ); } }
Dependencies injected via setter/property injection are not available until after the instance has been created – it’s pretty easy to visualize, just imagine doing it by hand: first you create the new instance and then you set the properties.
The most common solution to this problem is to remove the code from your constructor and place it into a public method with [PostConstruct] metadata placed above it, like so:
[PostConstruct] public function init():void { // all dependencies have now been satisfied }
Instead of using property/setter injection you can use constructor injection, simply define your dependencies as constructor arguments.
A word of warning about constructor injection: Due to a bug in the Flash Player (pre 10.1), full type information for constructor arguments is only available after the affected class has been instantiated at least once. To work around this bug, SwiftSuspenders (the default DI/IoC framework that Robotlegs uses) checks if type information for the arguments is available when performing constructor injection. If not, SwiftSuspenders will create one throw-away instance of the class. Because of this behavior, it is important not to start any complex processes in constructors of classes that are used with constructor injection.
Make sure to override the clone() method of your custom event class. Events can not be re-dispatched without doing so – even non-bubbling events. It is considered best practice when creating custom events to override clone().
Ensure that you don’t have a property or method with the same name as the package that your class is in. For example:
Package: com.company.project.area.view
In a class in that package: public var view:SomeView;
Please visit knowledge.robotlegs.org