Custom serialization and deserialization . . but only on the client

I have read a lot about IExternalizeable lately.  I need to do some custom serialization of AMF data coming across the wire but I can’t figure out how to get done what I need! It seems like IExternalizeable would do it.  (If you want some details on IExternalizeable then Josh has a good post on it and there are quite a few others out there too.)

The general idea though is that if you have a class that is getting serial/deserialized and it implements ISerialized then the writeExternal and readExternal methods will be called.  The default action is just to read/write all of the public properties & getter/setters.  But if those methods get called then you have access to the “raw” AMF data and can read just what you want (and put it where you want) and write just what you want to the AMF stream that gets sent.  Unfortunately, to get this to work you have to have the classes on BOTH sides of the wire implement their version of it. (Both Flex and Java for instance.)

I don’t want to do that.  The Java team working on the services has done a great job of creating the services and I just don’t want to meddle with things on that side any more.  Everything is already as clean as it needs to be.  I just want to write my OWN serialization logic!

I’ve poked around the RPC package.  I found the AMFX* methods which I could override.  But I’m not dealing with XML data but AMF.  And I can’t find the classes that do the same for the binary AMF data; just the XML.  I did find a few places that seem like I could insert some code and make some stuff happen.  In the Chanel class or some such.  I’m going to poke around some more and see what I can do.  But if anyone out there has an answer for me then please let me know!  I’ll post more on it here if I figure it out.

In case you’re interested in WHY in need this kind of customization, here is what I’m trying to accomplish.  My model has a number of properties that are tagged with a custom [Shallow] meta-data tag.  If that property is shallow then when I’m serializing that property then the only property that needs to be added is the ID.  Those objects labeled shallow are potentially HUGE and I really don’t want to have the whole thing sent across the wire.  I would like to either create a new instance of this property to be serialized with all values null except for the ID.  I can’t mark all of the values of this property [Transient] because there are other instances where I DO need those properties to be populated and sent.

Going the other way, I have a “global static model” that I want to update rather that add to.  While deserializing my AMF data I would prefer to see if a matching object has already been instantiated and instead update that object’s properties rather that create a brand new one.  I’m currently doing that with the already-created objects but there are some instances where implicit setters fire things that I don’t want to be fired unless it is the instance that is in the “global static model”.

(Arguements for/against the merits of a global static model don’t interest me right now . . . this has already been discussed a lot for this project.  The service layer has been changed from something that was previously JSON and being that the serial/deserializer was something custom-written what I’m trying to accomplish wasn’t an issue and was easily accomplished.)

Introducing: The Peanut Butter Logger (Flash-friendly AS3 logging)

The Flex logging framework is pretty cool.  For an old skool Flash Hack like me it was a huge step up from the trace() that was pretty much our only tool back in the day.  Some of us rolled our own solution in the AS2 days and there were even a few projects around the idea.  But there was never a great way of getting our important debugging info to a helpful place.

And of course the Flex logging framework is for . . . Flex.  I have a bitter-sweet relationship with Flex and the fact that the logging framework isn’t something that’s uber-portable is a little frustrating.  But no matter; there was enough I didn’t like about the framework so it was an even better opportunity to roll my own.

I’ve been using this logging framework since the early AS3 days and finally thought that it might be helpful to provide it to anyone else who is interested in using it.  The usage is about the same as the Flex framework:

var logger:PBLogger = PBLogger.getLogger("company.project");
logger.debug("peanut butter is awesome");
logger.warn("We are almost out of honey!");

The logs are automatically trace()ed. Additionally though (and here is the fun part) you can very easily build ‘bridges’ to pipe the output somewhere else. I’m a big fan on Antropod. But I don’t want to write all of my logs specifically to the Antropod output. What if I want to also pipe my FATAL logs to a service or another socket or something? When I start a project I call PBLogArthropodBridge.initialize(); and all of my logs are now piped into the Antropod debugger. Handy no?

I’ve also tossed in there a Flex logging framework bridge. Using this you can just toss this into an existing project that is using the Flex logging framework and all of your logs will get piped into the Flex logging framework by similarly calling PBLogFlexBridge.initialize();.

I hope that this thing will be pretty easy for people to use. You are welcome to grab the project or just the .swf. If there is enough interest in this code then I might make a real project out of it. This is an important dependency to the command framework that I’ll be releasing next. Please let me know if you find it useful!

Facebook API version 2 Project Setup Walkthrough

Update:  The AS3 Facebook API is now under Adobe’s Umbrella!  I have spent many many hours on this pet project of mine and I am now very happy to relinquish control to some very talented programmers on the Adobe team.  I will still be involved in the API community and will be consulting with Adobe about the features and future of the API so I’m not going anywhere.  But the API is going to be much much strong because of this transition.

If you’re looking for instructions on getting started then the Facebook Page on Adobe’s Developer Connection is going to be a MUCH more educational source than this post.  It’s just a few weeks old and already out of date. :P There have been some architectural changes to the API since this tutorial was released (all for the better!) so make sure to pay attention!

Read more

Maven + Flex

I wish this were a post explaining how to use Maven with Flex. I’m afraid this is rather documenting the journey. If you’re lucky (and I am lucky too) I’ll have an additional post or two explaining how I got this to work.

Update: After getting some help from Velo (the very helpful author of the flex-mojos project) I finally got things working. Only THEN did I come across this blog entry that outlines, well, pretty much everything I was looking for. Thanks Ryan Knight!

I’m a big fan of using Ant to build my Flex projects. I have a pretty standard way to setting up my projects now. I’m a copy ‘n paster and when I start a project I drop in my ’standard’ build.xml file. This puppy will build a .swf (or a .swc with just a few changes), will inject the SVN revision number into the .swf, can document (ASDoc style) the project and will package everything up into .zip files. So now I’m comfortable with it. It’s easy it’s fast. I understand how things work.

But I’m working on a project that is mostly Java. The collection of projects are managed by Maven. And now I’m trying to integrate a couple of Flash projects and I’m kinda lost. The mindset of Maven seems to be quite different than Ant. From what I’m reading online people who like Maven REALLY like Maven. It’s almost a religious thing. And while I can subscribe to the benefits the difficulties I’m having trying to understand everything is frustrating. While Ant is “procedural” (”it’s not a scripting language!”) Maven seems to be “model based”. I guess? It’s driven by POM files (Project Object Model). And (from what I understand) the POM files outline the details of the project and then the commands you execute (build, package, document, even create eclipse project settings) use the properties outlined in the POM file to execute. You don’t outline WHAT you want to do (like you do in Ant) you just outline the details of the project essentially defining HOW.
Read more

The Contract Game

Update: Well I just couldn’t do it. I tried. I wanted to. Contracting seemed like a wonderful adventure. But I was just offered a position at a great company that was just too good to pass up. I’m sure that I would have spent a lot of time looking for fun projects I could get paid to do. Instead I’ve got a steady stream of really kick-ass fun projects to do without the stress of looking. I’m working with a great and very smart team (mostly Java devs but I won’t hold that against them). I might consider a few small (really really fun) projects, especially if it relates to Flash on Facebook. But it’s nice to be in the pace of a regular gig again.

- – -

After a pretty good stint as a salaried employee I am taking to the freelance field once more. I think it’s going to be a continual cycle for me; freelance, salary, freelance, salary, . . . retire, freelance, retire, freelance. But right now I am in the freelance part of the cycle and looking for clients with some exciting work that needs to be done.
Read more

Next Page »