Category: ActionScript

  • How to trace every remoting call without ServiceCapture

    This isn’t a replacement for ServiceCapture; it should definately be used when you are doing some serious debugging between your client and server (or HTTPLook which isn’t as good with AMF traffic). However, if you have your own debug window, or just want another way to do it all in Flex 1.5, Flash MX 2004, and Flash 8, here’s how:

    import mx.services.Log;
    import mx.remoting.Service;
    
    private static var contructedApp:Boolean = contructApp();
    
    static function contructApp()
    {
            Log.prototype.onLog = function(message:String):Void
            {
                    trace(message);
            };
            _global.mainLog = new Log(Log.DEBUG, "mainLog");
            Service.prototype.log = _global.mainLog;
    }
    

    I believe that’ll show HTTPService calls for Flex 1.5 as well. Naturally, you can route trace in the onLog to whatever you want, or even use a Delegate to have the onLog function point and/or do something entirely different.

  • ValueObject Grind

    The backend developer is done, and loads of CFC’s are freshly down from Subversion for my perusal. Since I’m using Cairngorm for this Flex 1.5 project, I do a series of enapsulated steps to tie my front-end to the back.

    1. Open his CFC’s, find a method I need, and write a business delegate for it
    2. write a Command to launch the Delegate, and post it’s data on the ModelLocator
    3. add the necessary command constant names for EventBroadcaster in the Constants & Event classes
    4. open up the CFC value objects that the back-end developer has done, copy and paste the variable names into a Value Object class, and finish the class
    5. Since we are using ColdFusion pre-7.0.x, we can only get generic transfer objects back from the server (unlike AMFPHP or OpenAMF). So, we have a Factory class create Value Objects from the Transfer Objects ColdFusion sends back in the Delegate. I write the methods to create them as well as give back arrays of them.

    …this is where things start to suck. It’s not hard; you just convert uppercase property names to camel-case’d Value Object class property names like so:

    public static function getUserVOFromUserTO( p_to : Object ) : UserVO
    {
            var user : UserVO = new UserVO();
            
            user.firstName = p_to.FIRSTNAME;
            user.lastName = p_to.LASTNAME;
            user.userID = parseInt ( p_to.USERID );
            
            return user;
    }
    

    However, our value objects have a lot more property names, some have arrays of other vo’s they link to, and we have a lot more value objects since this is an extremely large project.

    Hard? No. Tedious? Damn straight… It is extremely important we get strong-typing to ensure the data we are using is correct and easier to debug if we find a problem. Using a for loop in the above with a toLowerCase() could work, but then you are assuming that data sent from the back-end is correct. Even worse, while CFC VO’s are somewhat easy to read since most properties are up top, some have linkages with other items (because of linked tables, many to one relationships, etc.), thus you cannot necessarely view it as a 1 to 1, CFC to client side VO relationship.

    A monkey could do this shit. That’s the rub; most programmers who make money start to recognize long, repetitive tasks, and the first question they ask themselves is, “Can this be automated?”.

    Flex 2? Sure, right click on a CFC, generate ActionScript VO. Flex 1.5 using ColdFusion >7.0.x? Nope, not without sacrificing strong-typing. You can get away with that in smaller scale apps, but not enterprise applications.

    BLEH!

    …speaking of monkey’s, maybe I could teach a Bathroom Monkey to code VO / TO conversion functions… hrm…

    My manager says writing CRUD operations is worse (which is automated in Flex 2 as well btw for ColdFusion). I certainly don’t evny the back-end guys, and will happily make VO’s in this Factory all day and smile when I think of what they most go through.

    BTW, I’ve unsubscribed from the 10 billion email lists I was on, so if you don’t see me answering questions, it’s because I am not receiving any emails (Flashcoders, Flexcoders, etc.). I need a break from lists.

  • ActionScript 3 Cheatsheet: flash.display.*

    Thotskee posted on the Flashcoders mailing list a link to an ActionScript 3 cheatsheet he made. It currently lists most of the classes in the flash.display package. That must of been a ton of work, I’m sure. Now that he’s set the bar so high, he’ll need to not only finish the display package, but also the others. Thankfully, I’ve reorganized my home office, so now I have room to post on my wall when he (or those that offer to help him) get them all done!

    Combine that with the Flex 2 mx API poster from Rocketboots, and my office will be awash in ActionScript. w00t! Thanks T!