Blog

  • AMFPHP 1.0 Works with Flex 2 / Flash Player 8.5 Alpha

    Thanks to Patrick Mineault, Renaun Erickson, Dave Wolf, and Peter Farland.

    To get AMFPHP to work with the Flex 2 Alpha, you need to:

    1. Extend NetConnection just so 3 methods can be added to it
    2. Have your gateway connection extend that new class
    3. Have the new encoding set to AMF0
    4. Make your calls using “YourClassAndPackage.method”

    The extended NetConnection looks exactly like this:

    package
    {
            import flash.net.NetConnection;
            
            public class NetConnection2 extends NetConnection
            {
                    public function AppendToGatewayUrl(append:String):Void
                    {
                    }
                    
                    public function AddHeader():Void
                    {
                    }
                    
                    public function ReplaceGatewayUrl():Void
                    {
                    }
            }
    }
    

    And some psuedo code for calling your server:

    // import the internal classes
    import flash.net.Responder;
    import flash.net.NetConnection;
    import flash.net.ObjectEncoding;
    
    // import your custom class
    import NetConnection2;
    
    public var gateway_conn:NetConnection2;
    // setup your jazz
    var gatewayURL:String = "http://server.com/amfphpfolder/gateway.php";
    gateway_conn = new NetConnection2();
    gateway_conn.objectEncoding = ObjectEncoding.AMF0;
    gateway_conn.connect(gatewayURL);
    // call back functions
    public function onPingResult(event:Object):Void
    {
            // success!
    }
    
    public function onPingResult(fault:Object):Void
    {
            // loop through fault object
    }
    // make a method call on
    // a PHP class
    var r:Responder = new Responder(onPingResult, onPingStatus);
    gateway_conn.call("YourPHPClass.theMethod", r);

    You can pass as many parameters you want starting from the 3rd parameter, on.

    Bad news is, mx.remoting.RecordSet converted recordsets for you in Flash MX 2004 & Flash 8. Since that class doesn’t exist in Flex 2, you can either wait for Adobe to do it, do it yourself, or convert plain arrays to meaningful data.

    Remoting with strong-typing… mmmmmm…

  • How to tell the difference between Web 1.0 and Web 2.0

    Even though there is no such thing as Web 2.0, this is still the best comparison I’ve seen. That so made my day… I fell out of my chair laughing. I love the interweb.

    How to tell the difference between Web 1.0 and Web 2.0

    Via The Roman Empire.

  • Automating SWC Creation in Flex 1.5

    Flex was made for true software developers. I apparently am not the target market of said demographic, or have yet to see the benefit of casting off the usage of clicking graphical buttons.

    Suffice it to say, there isn’t a symbol to right click on with an “Export SWC…” in the context menu like in Flash. Since Yahoo! Maps was created this way, however, it must still be good, right?

    A program called “compc.exe” creats SWC’s in Flex. You point it at an MXML or AS file, tell it where your classes root folder is, and tell it what to name the the SWC file. There are a lot more parameters you can use the docs, but those main 3 are all you need to create SWC’s.

    SWC’s are basically .zip files that contain your packaged component, and potentially other assets. They are what jar files are to Java. They can contain non-graphical, compiled assets for portable class libraries, or even images that your component needs to draw itself.

    They are really nice in Flex because you deploy with your app, greatly simplifying the amount of files in your project. Additionally, you can deploy them on the server so all applications on your Flex server compile with the same SWC.

    Since I was constantly testing a component recently, I had to keep remaking the SWC. Here’s a simple script you can paste into Notepad, and save as a .bat file on Windows. Then, all you have to do is double-click the file, and it’ll recompile the SWC for you.

    cd c:\program files\macromedia\flex\bin
    compc -o "C:\mypath\my.swc" "c:\mypath\mymain.as" -root "c:\mypath\"

    Ensure there is a carriage return after the “bin” so the compc part appears on it’s own line.

    You can obviously automate this in other build tools like ANT.

  • Dynamic Icons in a ComboBox

    Wrote this example for a gent on the Flashcoders list. Didn’t want an orphan page on my site, so linking to it from here. Shows how to use a cellrenderer in a ComboBox to show an icon. I should of only changed in the icon in the setValue function if it changed, like so:

    if(lastIcon != item.icon)
    {
       lastIcon = item.icon;
       image_ldr.load(item.icon);
    }

    That would of prevented the flicker you see when you roll over the items. The more I code in Flash, the more I love Flex. Flash is still faster though, no doubt.

    Icon in a ComboBox using a cellrenderer