Iterating a Filtered Collection

Okay, nothing profound here but thought I’d post as it’s a common question.

If you have filtered a collection,

ex

var ac:ArrayCollection = new ArrayCollection();
...
...
ac.filterFunction = myFilter
ac.refresh()

but you’d like to iterate over / access the unfiltered collection, simply use the .list property


var items:IList = ac.list

cheers

Josh

Flex 4 Gumbo Compiler Benchmark

‘Benchmark’ is being used pretty loosely here. I just got back from MAX and thought I’d check out the new compiler performance.

In addition to the exciting new display logic separation (Spark Framework), the SDK team has worked on speeding up compilation.

I compiled (incremental build) a project containing 57K lines of code (34K AS3, 23K MXML) under the 3.1 SDK via FlexBuilder. The compile took 40 seconds.

I then pointed FlexBuilder to the Flex 4.0.0 SDK. Make sure you update the ‘Require Flash Player Version’ on the Flex Compiler settings page to 10.0.0. If not you will receive errors including

1046 type was not found or was not a compile-time constant Matrix3D

After building the project I then preformed the same incremental build under 4.0.0 (Gumbo). The compile took 25 seconds.

Results:

SDK 3.1: 40 seconds
SDK 4.0.0 (Gumbo): 25 seconds

That’s not too bad, only ~62% of my original compile time.

AMFPHP Class Mapping Primer [1.9 beta]

Thought I’d post a simple AMFPHP class mapping primer.

I ran into a wall after re-arranging my VO / DAO package structure on the server, learned a few things in the process and thought I’d post .

I’m assuming your using AMFPHP 1.9 beta.

Class mapping allows your php backend and actionscript frontend to pass strongly typed variables back and forth. The benefits are obvious so I won’t cover them here.

If your not after any detailed information here’s a quick set of samples classes to get you going.

PHP


// LoginVO.php is saved as {$voPath}/com/dl/app/LoginVO.php
class LoginVO
{
   var $_explicitType="com.dl.app.LoginVO";
   public $username;
   public $password;
}

AS

package com.dl.common.Login.model.vo
{
   [RemoteClass(alias="com.dl.app.LoginVO")]
   public class LoginVO
   {
      public var username:String;
      public var password:String;
   }
}

That’s it. If your after more options and detailed info, keep reading.

Sending Strongly Typed Objects from PHP to ActionScript via AMFPHP

In PHP

You have a few options (choose one).

  • Your class can declare a variable named $_explicitType;
  • The most common approach is to use the $_explicitType class member:

    class LoginVO
    {
       var $_explicitType="com.dl.app.LoginVO";
       public $username;
       public $password;
    }
    
  • You can set $GLOBALS[‘amfphp’][‘outgoingClassMappings’][‘localclass‘] = ‘remoteclassAlias‘;
  • e.g.

    $GLOBALS['amfphp']['outgoingClassMappings']['myclass'] = "com.dl.myapp.MyClass";

    Note that the local class name associative key (‘myclass’ above) must be in lowercase with the current release of AMFPHP.

  • Rely on the reflection class (PHP 5+)
  • If your install of PHP has the ReflectionAPI you can let AMFPHP do the work *for* you. I found a few cavets using this approach on servers who’s OS uses backslashes natively. If this is the case, AMFPHP will only send the name of the class and not include any package info. There are two simple code changes you can make in AMFPHP to get around this, just drop me a line if your interested (hopefully they’ll be commited in the next release of AMFPHP).

    In actionscript

    Here to, you have a some options,

  • Use [RemoteClass] metadata tag to specify the remote class alias
  • package com.dl.common.Login.model.vo
    {
       [RemoteClass(alias="com.dl.app.LoginVO")]
       public class LoginVO
       {
          public var username:String;
          public var password:String;
       }
    }
  • Use registerClassAlias()
  • registerClassAlias(“com.dl.app.LoginVO”,LoginVO);

    Make sure your actionscript project contains a reference to the class. See my previous post for more info.


    Sending Strongly Typed Objects from ActionScript to PHP via AMFPHP

    In PHP

    Rely on the class having been registed in ActionScript with the server’s correct package [directory] structure (relative to AMFPHP’s VO base path $GLOBALS[‘amfphp’][‘customMappingsPath’]). If this is the case you, your all set.

    Note: If you haven’t already you’ll need to make sure $voPath is pointing to the correct directory in AMFPHPs global.php

    Define $GLOBALS[‘amfphp’][‘incomingClassMappings’][‘remoteclassAlias‘] = ‘localclassPackage‘. (e.g. $GLOBALS[‘amfphp’][‘incomingClassMappings’][‘com.dl.as3.userVO’] = ‘com.dl.userVO’);

    In ActionScript

    Again, you’ll need to use one of the two following…

  • Use [RemoteClass] metadata tag to specify the remote class alias
  • Use registerClassAlias()

    For more info check out

    AMFBaseSerializer.php’s getClassName() function

    AMFBaseDeserializer.php’s mapClass() function




    AMFPHP Complex Classes – Yeah I knew that

    Just blew half an hour tracking down something I *knew* I’d done before. Thought I’d post here for future ‘lapses.’

    To return a typed object from PHP to the flashplayer the process is simple, declare a variable called $_expicitType in your PHP class
    e.g.
    class SummaryVO
    {
    var $_explicitType = "com.dl.SummaryVO";
    $standards = array();
    $levels = array()
    }

    In your corresponding ActionScript class use the RemoteClass metadata tag

    package com.dl
    {
    [RemoteClass(alias="com.dl.SummaryVO")]
    public class SummaryVO
    {
    public var standards:Array;
    public var levels:Array;
    }
    }

    Note the values for $_explicitType and alias are arbitrary, they can be what ever you’d like, as long as their the same in AS and PHP (provided your only conerned with PHP=>AS mapping).

    Okay, so what happens when you have ‘complex classes’ you’d like to return? Complex meaning a class who’s members are made up of other ‘custom’ class instances.

    Let’s say, for example, that in our later code example ‘standards’ was an array of ‘StandardVO.’ The problem I ran into was that I was getting a typed ‘SummaryVO’ back from AMFPHP, however my class members were not typed, just generic objects. I checked and I had taken the necessary steps to use strongly typed SummaryVO and StandardVO classes, yet the StandardVO was coming back as a plain old Object.

    We’ll it turned out in my development flurry I hadn’t used a reference to the ‘StandardVO’ class yet!! Simply declaring an instance of StandardVO did the trick (i.e. var placeHolder:StandardVO). You could also you the includes class […] compiler option.

    Moral of the story, be sure the complier includes a reference to any class you want strongly typed from your RPCs.

    AS3 PureMVC Dynamic Modules

    Okay, I’ve had some questions on refactoring my PureMVC dynamic modules classes to support AS3 projects (i.e. no flex).

    I’ve posted a sample app that does just that.

    I threw this together off the cuff, so don’t expect too much 🙂

    The app (10K) simply loads 6 modules dynamically, 3 “RedTint” modules and 3 “GreenTint” modules (4k each). The app sends a notification every second containing a random color. The loaded modules pick up on this notification and display the color – each with their corresponding tint.

    Keep a close eye on Cliff’s Pipe utility as these classes may soon be obsolete 🙂 Until that time, I hope you might find this useful – if you do, drop me a line and let me know.

    I’ve got some time between projects if anyone is looking for some RIA development…