Monday, August 10, 2009

Installing Flash Player 10 Debug on 64bit Ubuntu

I just finished installing the Flash Player 10 debugger on my 64bit Ubuntu machine. All props go to "Me and Ubuntu," with the article located here:
http://meandubuntu.wordpress.com/2008/08/20/flash-10-rc-on-ubuntu-amd64/

It involves using nspluginwrapper and some other libraries to emulate a 32bit environment for Flash Player to run in. Totally rad.

Labels: , , , ,

Thursday, July 30, 2009

Spring Actionscript 0.8: My Review

Let's face it. AS3 needed an IoC container. Spring Actionscript delivered it. In an older post, I compared Spring Actionscript and Parsley as IoC containers and the main thing missing from Spring Actionscript (that Parsley had) was documentation. Now, with the release of Spring Actionscript 0.8, that issue is solved.

The documentation available at Spring Actionscript's site (link above) is awesome. It is in keeping with the main Spring IoC container's documentation, as well as other large libraries such as Hibernate's documentation. The documentation is pretty extensive and the feature list is growing by the day. It's becoming easier and easier to throw together a project with Spring Actionscript.

One of the new features that I had originally requested for a while back is autowiring. If you're not familiar with autowiring, it is something that will ultimately save you a lot of lines of configuration code and a lot of time. Autowiring is the process by which an IoC container finds and injects dependencies automatically, either by type or by name. Rather than writing something like this:

<object name="myObject" class="com.something.else.SuperDependency">
   <property name="megaDependency">
      <object class="com.something.else.MegaDependency"/>
   </property>
</object>

You can write something like this:
<object class="com.something.else.SuperDependency" autowire="byType"/>
<object class="com.something.else.MegaDependency"/>

In this case, "MegaDependency" is automagically injected into "SuperDependency" because of a few things: 1) The object tag describing "SuperDependency" has the autowire attribute set to "byType", 2) "SuperDependency" declares a property "megaDependency" of type "MegaDependency". Basically, what is happening behind the scenes is that Spring Actionscript is using introspection and runtime reflection (provided by the AS3 Commons Reflection library) to analyze the fields (getters/setters/instance level variables) of a type, and then is looking for other objects managed by the IoC (Inversion of Control) container which match that type. If it finds an object eligible for injection, it automagically injects that object into the autowired one, saving you 2-3 lines of code per object.

Granted, the process above describes autowiring by type. There is another method of autowiring known as autowiring by name, but that seems pretty self-explanatory, right? Find an object in the IoC container whose name matches the name of the referenced property. Eg: if "SuperDependency" has a property called "megaDependency," the IoC container will look for an object within itself called "megaDependency."

Another game-changing feature of Spring Actionscript 0.8 is Stage autowiring. When used in Flex, Spring Actionscript can now autowire stage objects. By listening for the Event.ADDED event on the Stage, Spring can tell when display objects are added to the stage. When this happens, certain properties can be autowired.

Check out this example:
...
[Autowired(mode = "byType")]
public var myDependency:MyDependency;

[Autowired(mode = "byType")]
public function get myOtherDependency():AnotherDependency { ... }
public function set myOtherDependency(value:AnotherDependency):void { ... }

Assuming this is a class that extends flash.display.DisplayObject, when this instance is added to the display list, Spring Actionscript is notified by the Event.ADDED event, and it attempts to autowire this instance. By looking at the metadata, Spring Actionscript will autowire any necessary properties declared by your class, saving you a lot of work.

Basically, this version of Spring Actionscript is amazing. I love it. By working with it, I have saved tons of time, both in development and in preventing epic madness in the future.

The Spring Actionscript team has also been extremely helpful in fixing a few bugs related to the release. The first major one of these was Module autowiring on the stage. The problem with using Modules in Flex with Spring Actionscript is that Spring is counting on all class definitions being in the main ApplicationDomain. When loading a Module, by default a new ApplicationDomain is created for memory purposes, and the Module's classes are loaded into it rather than the main ApplicationDomain.

Unfortunately this poses a problem as Spring is unable to find class definitions for all Module classes. However, the Spring Actionscript team has been very helpful in addressing the bug and trying to provide a fix. At this point, in the trunk, the issue has been patched but not fixed by preventing Modules from being autowired. Hopefully in the future, a fix will come so that we'll be able to use stage autowiring anywhere, no matter which ApplicationDomain the classes are loaded into.

Another issue that has been fixed since the 0.8 release is complex property resolution. Spring Actionscript uses the Java property format (my.complex.property = something), and that format usually allows for complex property resolution (my.complex.property = ${my.other.property}/tk), but this wasn't working with the 0.8 release. Fortunately, I have been told that this functionality is working great in the trunk, but I have yet to try it out.

Again, mad props to the Spring Actionscript team! Thank you so much for an awesome IoC container for AS3! Looking forward to the next release!

Technorati Tags: , , , , ,

Labels: , , , ,

Tuesday, July 28, 2009

[AS3] Flex Unit 4

I just wired up the latest version of Flex Unit 4 and it is impressive to say the least. For the last week or so, I've been messing around with the version that ships with Flash Builder 4, but I wanted to get up with the latest because of all of the awesome goodies it comes with.

The thing I am really excited about is the new metadata-driven model. It's almost as convenient to use as JUnit (but it still has a few things to improve upon). Finally, we're able to have annotated test cases and test suites and thus are not forced to extend a class or implement an interface. All test-related configuration is done at runtime by the framework and via introspection. A great article that got me started can be found here on InsideRIA.

The framework seems incredibly intelligent. You can even specify if you expect a method to throw an error with a simple metadata parameter. If the test method does not throw that error, it is considered a failed test. I haven't found anything about the actual framework that I don't like. It is a huge improvement over previous versions of Flex Unit and a good step toward standardizing unit testing across platforms.

One cool thing that I found inside of Flash Builder 4 is how easy it makes it to run Flex Unit tests. By right clicking on an Actionscript/MXML file, you can choose to "Execute FlexUnit Tests...", which I really like. The downside to this is that Flash Builder 4 currently prefers an older version of Flex Unit, and encourages you to manually extend a class and follow test naming conventions etc. The upside to running Flex Unit tests inside of Flash Builder 4 is that it will actually show your test results within Eclipse.

This alone is a feature that's been missing for an extremely long time. Being able to run unit tests within your IDE is a huge productivity boost. Having to manually launch a SWF that displays its test results within itself is at least a few extra steps that bog down one's workflow. Unfortunately, since I'm using Flex Unit 4 rather than the Flex Unit that ships with Flash Builder 4, I have to launch my tests and compile them separately, but at least we're now moving in the right direction. Once you understand the flow of working with a LocalConnection, passing data from Flash to, let's say, Java, really isn't that hard. All you need is to master the AMF encoding, and the LocalConnection protocol, both of which have been done. Then, you connect both ends together, pass some nice data objects about test results back and forth, and when the tests are done, call flash.system.System.exit(0) to kill the Flash Player instance.

All of this could be done relatively easy through the use of an Ant task, making the tests completely automated. I prefer building my applications with Ant, since I can use Ant on any platform and at any time and get the same results. Making a project portable is what separates it from the pack. It's easy to throw together a sloppy project that will only compile in a very specific configuration and setup, but with the right planning, you can have a nice project which builds in Ant, anywhere.

Anyway, I digress. Flex Unit 4 is definitely worth checking out. Go out there and start messing with it!Technorati Tags: , , , , ,

Labels: , , , , ,

Monday, July 27, 2009

Vote for a Linux version of Flex/Flash Builder!

If you're on the same page with me in wanting a Linux Flash/Flex Builder edition, you can vote for it here:
http://bugs.adobe.com/jira/browse/FB-19053

Make your vote and comments count! Even if you don't use Linux per se, please vote for the issue. By doing so, you'll be expanding and encouraging the Flex/Flash community to another OS!

Labels: , , , ,

Friday, July 24, 2009

[Linux] Flash Builder 4: Will Adobe Help Us?

The question that has been plaguing me for some time now is this: Will Adobe release Flash Builder 4 for Linux? I don't think I'm alone on this one. Most every linux-using Flash/Flex developer needs a development environment to use. And up to this point, there really isn't anything out there.

Sure, there's Flex Builder 3 for Linux, but it has extremely limited capabilities, and you have to hack it just to get it to work with Eclipse 3.4+. Did I mention that it won't install in a 64bit JVM? Yes, I was able to get it working, but it's a huge pain for something that shouldn't be. It's been a beta for nearly a year now, and with no real hope in sight. Since Adobe just released Windows and Mac beta editions of the new Flash Builder 4, what does it mean for us? Is there a plan out there for Adobe to save the day?

Yes, there is FDT. Enough said. But the full-flavored version of FDT is like $600+! I don't know about you guys, but I don't have that kind of money laying around. However, FDT IS DOING SOMETHING AWESOME and giving their best product away for FREE for open source project teams. I guess I just need to jump on it and get my secret projects (insert evil laugh) into the mainstream. Even so, MXML support is limited, and as far as I know, you can't visually create Flex applications like you can in Flash/Flex Builder.

So my statement is this: Help us help you Adobe. There ARE people out here that are waiting desperately for a Linux Flash/Flex IDE to come out. We DO have money and we're willing to spend it. Just please try and meet us halfway :)

If there were any other way, we'd do it. But there isn't. Wine is a long ways off from being able to virtualize a Windows JVM, so our only real option is to run it natively on Windows or Mac. Hear our cries, Adobe, we'd love to give you money for your product!

Labels: , , , , , ,

Flex 4, Ant, and an OutOfMemoryError

I just started messing around with the new Flex 4 SDK beta, and man is it cool. The rework of the states system is reason alone to move now to Flex 4. Two-way data-binding, virtualization (I have not a clue as to what that means in Flex), and tons of other goodies look very promising for the Flex product line. Adobe, hats off to you for one-upping Flex 3, which indeed must have been a challenging feat.

Today, however, I ran into a problem with running the Flex MXMLC Ant task to compile my application. I kept getting a Java OutOfMemoryError whenever I'd try to compile. Initially, I wasn't seeing this problem, but as my application got more complex, like it always does, I couldn't be rid of the problem.

Luckily for you and I, a few people have run into this before and so I got a few pointers from a couple colleagues on how to work around the problem.

The first workaround I stumbled upon was a Windows-specific fix (for running ant from the command-line): http://n1aub0.cowurl.com | Apparently, you can set an environment variable "ANT_OPT" to include default JVM arguments when running Ant from the console.

The workaround that really fixed the problem for me in Eclipse was found on Sönke Rohde's blog. Mad props to Sönke for finding a way to fix this. Again this fix isn't something new to me, but it's just nice to have these links laying around whenever you run into them. Adjusting Java's memory size isn't necessarily an "easy" thing to do, so it helps to have a reference.

Friday, May 29, 2009

Java: Try...Catch...Finally Flow

Note to self:
JAVA WILL ALWAYS EXECUTE THE FINALLY BLOCK*.

Hence, this code will work:

public static void main(String[] args)
throws Throwable {
try {
if (true) throw new RuntimeException("WOWZA!");
} catch (Exception e) {
throw e;
} finally {
System.out.println("REACHED!");
}
}

Yes, Java's output stream will read "REACHED," followed by the exception trace.

Even this code will work, and the finally block will be reached:

public String getString() {
try {
if (true) throw new RuntimeException("NOOOOOOOOOOO!");
return "STRING";
} catch (Exception e) {
return null;
} finally {
System.out.println("REACHED!");
}
}

Hope this helps someone out there.

* The only time Java will not execute a finally block is when it can't: eg when the JVM is shut down or the current thread is killed outright.

Labels: