Blog

  • 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!

  • MovieClipLoader Oddity in Flash Lite 2

    Jeff from Custom Logic posted on the Flash Lite mailing list about a problem with MovieClipLoader. Basically, if you remove the MovieClip via removeMovieClip that is used in the load operation for the MovieClipLoader.loadClip, as soon as the image loads, you’ll get a “Unable To Load Data” error. For some reason this race condition is handled fine in Flash Player 9 and below, as well as the Flash Lite emulator in Flash 8, but not in Flash Lite 2.

    Solution is to encapsulate the load operation & removing of the MovieClip in a class that generates an event upon success since it cannot happen immediately.

    Non-class example (tested and works):

    function init()
    {
            mcl = new MovieClipLoader();
            mcl.addListener(this);
            
            load_btn.onPress = function()
            {
                    this._parent.doLoad();
            };
            
            kill_btn.onPress = function()
            {
                    this._parent.doKill();
            };
            
            // keep state
            abortFurtherLoading = false;
            isLoading = false;
            
            fscommand2("FullScreen", true);
            
    }
    function doLoad()
    {
            // only load if we aren't already doing so
            if(isLoading == false)
            {
                    isLoading = true;
                    if(image_mc) image_mc.removeMovieClip();
                    createEmptyMovieClip("image_mc", 0);
                    mcl.loadClip("http://www.some.com/image.jpg", image_mc)
            }
    }
    function onLoadInit(p_mc)
    {
            isLoading = false;
            // if we should abort, go ahead and remove
            // the clip
            if(abortFurtherLoading)
            {
                    abortFurtherLoading = false;
                    removeTheClip();
            }
    }
    function doKill()
    {
            // if we are loading...
            if(isLoading == true)
            {
                    // ...wait till we're done
                    abortFurtherLoading = true;
            }
            else
            {
                    // ...otherwise, kill immediately
                    removeTheClip();
            }
    }
    function removeTheClip()
    {
            image_mc.removeMovieClip();
            delete image_mc;
    }
    
    init();
    
    
    
  • Speaking About Flex 2 for FMUG.az

    I’m speaking about Flex 2 this evening to the folks at FMUG.az, and it will also be broadcast & recorded via Breeze. I’ll be doing an overview of the technologies, and show some my favorite features through some code examples I’ve built. Specifically, I’ll be covering:

    1. What Flex 2 is & why you should care
    2. Flash Player 9 (formerly known as 8.5)
    3. ActionScript 3
    4. Flex Builder 2, the new IDE & plugin for Eclipse 3.1
    5. Flex Framework 2
    6. Briefly touch on Mystic, the ColdFusion 7.0.1 updater
    7. Briefly touch on Blaze, beta name for Flash 9

    I have an immense amount of material to cover in 2 hours, so I welcome questions before (comment on this blog), during, and after the presentation. You should come away understanding what Flex 2 is, what technologies make up Flex 2, and how each part can benefit your Flash, Flex, server-side, and/or general Rich Internet Application work.

    It starts at 6:30pm Arizona time, 9:30pm eastern time (GMT -5), and you can get the Breeze link from here.