As I noted earlier this week, Java is looking to be a second class language on the BlackBerry PlayBook, so most developers are going to be programing for it in ActionScript rather than in Java. This will take some adjustment, but ActionScript is not all that different. In addition to the webcasts that RIM has put together on the PlayBook, an older ActionScript for Java Developers webcast on the adobe website may be useful as well. In addition, here are a few things that have thrown me off a bit so far.
- draw() instead of invalidate(): When updating a GUI component you call draw() where you would typically use invalidate() in Java. This is actually a bit different because the draw() method is more equivalent to Java’s paint(Graphics g) method. However, as opposed to Java where you can’t really call the paint method directly, ActionScript allows you to directly call draw() in order to refresh your components.
- Access object variables instead of get and set methods: I’ve always been a fan of using public or protected variables instead of creating get() and set() methods for internal variables. ActionScript embraces this approach, although a little magic can be used to create get() and set() type behavior. This is even used for the default components, which can take a little getting used to.
- Reuse variables instead of locally scoping them: Unlike Java and C#, variables are not scoped locally. So for example whenever you use
for(int i=0;i<10;i++)
to loop through your array in Java, in ActionScript you would usefor(var i:int=0;i<10;i++)
the first time it appears in the method, and then reuse the variable in the form offor(i=0;i<10;i++)
for every loop after that.