Arp 3 Preview Release

Arp PizzaService sample application in Flex 2 and ActionScript 3

I've committed the first working version of Arp with AS3 and Flex 2 support into the Arp SVN repository.

You can check out just the AS3 version of the framework from:
http://svn1.cvsdude.com/osflash/arp/trunk/as3/

See just the code for the Flex 2 version of the PizzaService sample application here:
http://svn1.cvsdude.com/osflash/arp/trunk/samples/PizzaService/client/flex2/

(You can use Import... -> Existing Projects into Workspace to import both of those into your Flex Builder 2 workspace.)

The current Flex 2 version of the PizzaService sample application is a port of the Flex 1.5 version. While migrating it, I found that there wasn't support in Flex 2 for migrating applications that use AMF0 remoting (i.e., those built in Flex 1.5 and lower that use Flash Remoting). Instead of using the tag, and complicating the migration process, I decided first to create a migration layer to make it easier to port Flex 1.5 Arp applications to Flex 2.

The PizzaService application in Flex 1.5 defines a service in the ServiceLocator as shown below:

[as]var pizzaService:Service = new Service ( gatewayURL, null, "PizzaService", null, null );[/as]

In Flex 2, the call is slightly different and you use the new AMF0Service class in Arp 3:

[as]var pizzaService:AMF0Service = new AMF0Service ( gatewayURL, "PizzaService", null );[/as]

Similarly, in Flex 1.5 you call a server-side method through Remoting as shown below:

[as]var pizzaService:AMF0Service = ServiceLocator.getInstance().getService ( "pizzaService" );
var pendingCall:AMF0PendingCall = pizzaService.order( orderVO );
pendingCall.responder = new AMF0RelayResponder(this, "onResult", "onStatus");[/as]

To do the same thing in Flex 2 is as easy as replacing the Service, PendingCall and RelayResponder classes with the new migration classes provided in Arp 3 -- AMF0Service, AMF0PendingCall and AMF0RelayResponder -- as shown below:

[as]var pizzaService:AMF0Service = ServiceLocator.getInstance().getService ( "pizzaService" );
var pendingCall:AMF0PendingCall = pizzaService.order( orderVO );
pendingCall.responder = new AMF0RelayResponder(this, "onResult", "onStatus");[/as]

I want to thank Mike Potter for his RemotingConnection class, which extends NetConnection and makes AMF0 work in ActionScript 3. Arp 3 makes use of Mike's class.

This is a preview release of AS3 and Flex 2 support in Arp. As such, I'm releasing it without having tested it extensively. Please feel free to report issues in the comments of this post or to contact me directly with bug reports, etc. I am planning on creating another version of the PizzaService application that makes extensive use of Flex 2 features such as data binding, states, the tag, etc. (Consider this version the migration version.)

Known issues:

  • VOs being sent from remoting appear as plain objects in ServiceCapture. This may have something to do with how apply() works. If anyone has any ideas on this, I'd love to hear them. If you look at the invoke() method in the AMF0Service class, you'll see that the VO maintains its OrderVO datatype until the apply() call. Whatever is going wrong must be happening after this point.
  • I refactored the backend (to use pizzas instead of orders as the property). This may break the other clients (Flash 8 and Flex 1.5) I'm going to look into this now and update things if they are, indeed, broken.)
Creative Commons LicenseThe Arp 3 Preview Release article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.

12 Responses to “Arp 3 Preview Release”


  1. 1 JabbyPanda

    Thanks for posting this sample, this is first time I learn applying ARP framework to Flex code by source, before this example, there were not any known to me.

    One evident difference for me (comparing with Cairnigorm), is the absense of ViewLocator and ViewHelpers classes.


    In our own built in house framework we also turned down ViewHelper classes if favour to MXML files extending corresponding AS class like ARP does.

    Multiple MXML View classes communicate between via events dispatched by EventDispatcher, we had thought that ViewLocator brings too much coupling between independent AS classes.

    We would be happy someday to invite you to Ukraine to give you a presentation on our own framework ideas… currently applied to the legacy of our Flex 1.5 based code.

  2. 2 Mike Britton

    Thanks so much for this example — your work is superb. Any chance of an example that uses CF Remoting?

  3. 3 picmicro

    Thanks for this example but I was not able to find the file ArpAs3.as in svn (http://svn1.cvsdude.com/osflash/arp/trunk/as3/)

    Is it somewhere else in svn?
    Thank You

  4. 4 pic_micro

    Besides ArpAs3.as, I did not find Arp.as in svn.

    Thank You

  5. 5 Praveen

    Hi,

    I am a beginner in flex. For give me if i seem a bit novice. One of the issues that i have found working in flex is that I am not able to map the VOs from java to the VO in Flex. It gives me a type coerscion exception. Any solutions for this?

    Any help in this regard would be appreciated.

    Thanks

  6. 6 aral

    Praveen, which Flash Remoting server are you using? Also, are you using Flex 1 or 2?

    To see an example of how to implement this with Amfphp (the client-side will be the same for Java), see the Flex 2 sample app for Arp.

  7. 7 FlexibleGuy

    Hi….
    It’s me Praveen again…… Just registered so thats why the fancy name…..

    I tried out your example it works fine. But the problem i was referring to would be more appropriately explained by the TODO comment that has been left in AMF0Service.as.
    Please find it below:

    // TODO: Investigate why objects don’t show up with correct
    // datatypes in ServiceCapture (they are being as plain
    // Objects)
    // Is the apply() method somehow stripping them of their
    // datatype?

    Please let me know if anyone has been successful in finding any solution for this.

    Thanks for your replies…..
    Praveen

  8. 8 ktec

    Hi Aral,
    Finally had a chance to play with this, one thing i did find you may want to include is an addition to the RemotingConnection class:


    public function setCredentials(userId:String, password:String ):void
    {
    addHeader("Credentials", false, {userid: userId, password:password});
    }

    Then you can use:


    var gatewayURI:String = "http://localhost/gateway.php";
    var gateway:RemotingConnection = new RemotingConnection ( gatewayURI );
    trace("Setting service authentication")
    gateway.setCredentials("username", "password");
    var gateway:RemotingConnection = new RemotingConnection ( gatewayURI );
    var pizzaService:AMF0Service = new AMF0Service ( null, "PizzaService", gateway );

    in ServiceLocator.addServices method.

    I discovered this in some discussions between Jester and Patrick on the amfphp discussions.

    I’m still experiencing problems with my resultObj being undefined, but i assuming its unrelated. Anyways, great work as always!!

    keith

  9. 9 ktec

    Found it!!

    // Notice: *Not* resultObj.result as in AS2

    that’ll teach me not to read your comments…

    CancelOrderCommand.onStatus needs the same fix!

  10. 10 Chris

    Hello,
    any chance for sample pizza app with as3 and Flash.

    It was nice to went throught the project in as2, lernt a lot - now would like to do the same with as3

  11. 11 Aral

    Hi Chris,

    I’m not actively developing Arp at the moment but you can find AS3 and Flex 2 samples here:

    http://svn1.cvsdude.com/osflash/arp/trunk/samples/PizzaService/client/

    Hope that helps,
    Aral

  1. 1 ARP Framework (Aral Balkan) « Flash Dummy

Leave a Reply






Bad Behavior has blocked 0 access attempts in the last 7 days.