September 2005 Archives

Some notes about using OpenAMF

| 10 Comments | No TrackBacks

We've been using OpenAMF to connect a Flex client to a Tomcat server in the current project I'm working on. I'm impressed with how well OpenAMF works, but there were a few gotchas we ran across when trying to set up and configure everything. Here are some things to keep in mind if you decide to use OpenAMF in your own projects.

We use the Value Object pattern in order to transfer data between client and server. Rather than call a remote method with different types of parameters, we'll package everything up into a Value Object and send the Value Object over the wire. This is especially handy because with OpenAMF we can map an ActionScript class to a Java class. If we send a PersonVO ( defined in Person.as ) as a method parameter, we can type that parameter as a PersonVO ( defined in Person.java ) on the server.

In order to accomplish this, there are two things you need to do:

  1. Create a mapping in the WEB-INF/openamf-config.xml file on the server
  2. Associate the string name to the class instance on the client

For #1, open up the config file and add a mapping like this somewhere in the config file under the config root element:

<custom-class-mapping>
	<java-class>com.whatever.vo.PersonVO</java-class>
	<custom-class>com.whatever.vo.PersonVO</custom-class>
</custom-class-mapping>

For #2, we need to add an Object.registerClass() call on the client sometime during the application startup process:

Object.registerClass( "com.whatever.vo.PersonVO", com.whatever.vo.PersonVO );

The above is necessary to convert the ValueObjects received from the server into their native ActionScript 2 class equivalents.

The last item I wanted to mention is to be careful with your ValueObjects whenever you have complex types in them. For instance, if a PersonVO has a "books" array (of BookVO instances), it's very important that the books array is never initialized in the VO. That is, this code:

class PersonVO {
	public var books:Array; // of BookVO
	
	public function PersonVO() {
		books = new Array();
	}
}

... will cause problems when you get the data from the server. The constructor is called after all of the values are set, so you'll never get the right data from books because you're always overwriting it! Remember to keep your constructors in your ValueObjects empty or else you might overwrite data accidentally.

The reason we ran into the constructor issue was that we were creating some mock ValueObjects client side because the server code wasn't ready yet. In testing the client, instead of making an actual remote call we'd make a call that used setInterval to construct some VOs and pass them as parameters back, simulating the onResult method of Flash Remoting. Our VO constructors created new complex objects so that we could create our mock data easily. It was only when we switched from the mock calls to the real ones did we run into the issue, and boy was that fun to debug...

I hope this helps someone in the future using OpenAMF on their Flash / Flex projects!

Now, if only ColdFusion could map .cfc's to .as files as easily. I've used the _remoteClass trick in previous projects, but when you have VOs that contain arrays of other VOs that contain more VOs, it gets complex fast. We chose Java over ColdFusion simply because OpenAMF provided a more robust Flash Remoting solution, and made the client-server integration layer easier to write.

It's the little things...

| 10 Comments | No TrackBacks

Attention to detail is the difference between a good product and a great product. That's why I love the new Flash Professional 8 release...

I'm sure by now you've heard about all of the new features in Flash Professional 8. One of my favorite changes that won't get a lot of publicity because it's a little detail is "Test Movie."'

In previous versions of Flash, whenever you tested your content a new internal window was created. If you had your windows maximized then you'd see the .swf appear as a new tab, taking up all the available space. The problem I had with this is that most of the time I'd want to test the .swf at its regular size. Always starting out maximized inhibited my workflow.

So, I either had to restore the internal window to get it to be its regular size (an extra step), or not work with .fla files maximized. The latter presented a problem because it's harder to work on multiple files at the same time due to window overlap. Sure, Ctrl+Tab would switch between then, but I really liked the tab interface that appeared when your .flas are maxmized.

This issue was addressed in Flash 8. Now, whenever you publish a movie a brand new window appears at the default width and height of the .swf. No longer does it open an internal window. I absolutely love this feature, it really streamlined the "Test Movie" process.

This may seem like a small change, but it makes a difference working with the program day in and day out. If the killer new features don't inspire you to upgrade, maybe the little details that tend to go unnoticed will.

What other little things have you noticed in Flash Professional 8 that are improvement over Flash MX 2004 Professional?

New Design, New Site, New Me

| 14 Comments | No TrackBacks

I try to keep my personal entries to a minimum, but so much has been happening lately that I need to ramble a bit. The last 3 months of my life have been an emotional rollercoaster, but things are finally starting to settle down and I'm ready to move on into the next phase of my life.

As you may be aware, I had moved from the Lehigh Valley in Pennsylvania to Baltimore, Maryland late last year. I scored a really awesome job doing Flash development full time, working on a very large Rich Internet Application in the Health Care industry. Over time, we transitioned the application from Flash to Flex as it was a better fit for the project and we were able to make progress a lot faster. Thus, the basis for my "From Flash to Flex" presentation.

Anyway, things had been going well. In fact, in June I married my long-time sweetheart Jen and we spent 10 wonderful days in Jamaica. After the honeymoon, things started to get crazy. Jen had just graduated from college (with two degrees, in Mathematics and Computer Science). She started a job, but it turns out the job wasn't what she interviewed for and just wasn't right career-wise. So, she quit to pursue a different line of interest. In the meantime, I found out that my company just lost a hostile takeover battle that it was fighting for a over year. Layoffs were inevitable, a few weeks away.

Having a very unstable job situation and feeling the pressure, we started looking around for options. After a few weeks of searching, Jen was able to find a job in central Pennsylvania that was much more suited for her career-wise. I worked out a deal with my manager to work remotely and we packed our belongings and headed for Hershey, Pa.

Moving in and of itself is a stressful process, but moving and not having job security is rough. Thankfully, after Jen started work she found what she was doing to be enjoyable. I worked a few weeks from home, but as soon as the takeover deal was complete I was laid off from work. It was expected, and thankfully I had a good severance package as that gave me time to organize my thoughts and plan my future better.

I've been laid off for a few weeks now, and now that I think I've tied all of the loose ends, I'm ready to move on. Rather than try to find a full-time job in the area, I've decided to take a risk and pursue a full-time contracting career.

I've updated my website to reflect the change (and based the design on tictac). Thankfully, things seem to be off to a good start as I already have work lined up starting next week. I'm not sure how long the duration is ("indefinite, long-term potential"), but I'm excited to try something new and I'm curious to see where life is going to take me.

And of course, I'm going to try and remain a major contributor to IFBIN. IFBIN is a solution providing great software examples for learning and reuse. I've added quite a bit of code to Flash by Example thus far, and I'll be continuing to add more especially now that my time has opened up.

So, here's to the new me! I'm excited / terrified at the same time, but I think things will work out alright... If anyone has any tips about doing contract work full-time, I'd appreciate the insight. Comments welcome. :-)

Also, I only had IE6 and FireFox on Windows XP to test the new site design. Everything should be alright on OS X, but I don't have a copy around to test on. I'm mainly concerned about Safari, as FireFox should render correctly. If you encounter anything goofy, just let me know. You can use my sweet new contact form to get in touch with me.

From Flash to Flex presentation files

| 3 Comments | No TrackBacks

I've put the slides and example files from my presentation this past Tuesday available for download here.

The session went pretty well I think, and gave a lot of people a chance to see how Flex can be useful to them as Flash users. I had people approach me afterwards and say they had heard of Flex but didn't really know what it was or how it was applicable until after my presentation. I showed how to set up Eclipse and use Flex as a client-side compiler, and using Flex in this way was a big hit.

Keep in mind that all of the examples in the download were accompanied by an explanation and don't really say much just by themselves. Rob had video-recorded my session so hopefully that will make its way online at some point. Also, for those of you who already have Flex experience, the examples probably won't help you at all as they were meant to give an introduction to Flex from a Flash user's perspective. Feel free to check them out anyway...

Some links:

If you have any questions, look at the FlexCoders group, or feel free to email me personally and I'll try to get back to you in a reasonable timeframe. I get a lot of email so I can't promise you'll get an answer, but I do my best...

Good luck!

Flex.org - The Directory for Flex

Archives