UPDATE [08/25/08]: Source has been updated using PureMVC 1.0.5 MultiCore.

These days I’ve been playing around with the latest cool utility for PureMVC MultiCore AS3 called “Pipes Utility” developed by Cliff Hall. It’s a very helpful and powerful utility to communicate among all core actors of a module based application using PureMVC.

For a better understanding I created a basic example using modules. It’s just a simple app called “HelloPipes”, which loads and unloads a module for communicating with its shell using Pipes. Module and shell are acting as a core based on PureMVC MultiCore AS3.

The following example including full source may help anybody who is interested in the new Pipe Utility too ;-) .

Example

Full source

HelloPipesSource.zip (Downloads: 3023)

Tips using Modules, PureMVC MultiCore AS3 and Pipe Utility

  • Don’t import any classes of a PureMVC MultiCore module within the shell (main application) to avoid any issues at runtime loading and unloading a module. To define constants for using Pipes such as output and input pipe names, which are shared between shell and module, don’t use a reference to any actor. Use a simple “common” class instead, which stores only these constants for sharing by shell and module. Check the PipeAwareModuleConstants.as within the example above.
  • For communicating from shell to module and return without Pipes use well defined interfaces for the same reason mentioned before.
  • Clean up your module to avoid any issues loading and unloading it again. This may be helpfull for a successful garbage collection as well. Check out the code for the module within the example above, which uses an Interface called IPipeAwareModule. Using this interface the shell forces the cleaning up process of the module before the module will be unloaded.
  • Disconnect and unregister (if necessary) Pipes connecting shell and modules, when a module is unloaded.
  • Remove all PureMVC core actors of a module using facade.removeCore before a module is unloaded to avoid issues reloading it.
  • General issue: To reduce the file size of a module use the compiler option called load-externs. For detailed information check the Flex 3 Help: “Compiling modules – Reducing module size

Helpful links

Have fun! ;-)

26 Responses to “A basic PureMVC MultiCore AS3 example using Pipes Utility and Modules”

  1. Y.Boy Says:

    Good!

  2. Sep Says:

    Hi, when i click on the load Module all i get is the spinning clock, the module is never loaded. Also i notice that there isn’t any SimpleModule.swf anywhere is that the issue ?

  3. sectore Says:

    Sep,

    within source (“HelloPipes.zip”) you won’t find any SWFs or Modules. So you have to compile the Module before running the app. To compile the Module called “SimpleModule.swf” using Flex Builder just right click on SimpleModule.mxml -> Run as -> Flex Application.

    -Jens

  4. Sep Says:

    I got it working thanks! Could you tell me what are the differences between the pipe method and the Modularity methods, and why did you pick this one ?

  5. sectore Says:

    Sep,

    in short words: With Modularity you may define an own API for communicating between shell and modules using events or methods based on well defined Interfaces.

    The Pipes Utility has already implemented an API for communicating from shell to one or more modules (and / or back) in a loosely coupled way. Furthermore pipes can do a lot of other things, e.g. filtering or sending queues of messages and more.

    Personally I find that the utility is a hard stuff to understand, but at the end it will give you a lot of possibilities for using PureMVC MultiCore AS3 in a well defined way.

    -Jens

  6. Sep Says:

    Thanks sectore, I am starting an application with the PureMVC MultiCore AS3 and Pipe Utility, i like the decoupling concept, but i have a question in regards to the development of such an application. Every module has its own pureMCV MultiCore so i was thinking that i could preview them independently, like in Flash i create my “swfModule” from different fla and preview them for testing, but i think you need to load modules in an application to preview them ? Ideally I would like to separate everything in different application so everything is independent and then use the pipes for connections… is that possible ? or should every thing be in just one application ?

  7. sectore Says:

    Sep,

    there are different ways to organize your project for creating modular applications and it depends on your needs.

    If you would like to run all modules as a “standalone” version without the shell they have to include all sources of all needed classes (incl. Flex framework classes). That means that a module has classes that overlap with the shell’s classes, which increases the module size as well.

    Another way is to exclude all classes for a module which are used by module and shell as described here: “Reducing module size”. Using this way a module size are decreased, but it won’t run outside the shell. BTW: The example above based on it.

    I highly recommend chapters “Using modules in a single project” and “Using multiple projects” at “Creating Modular Applications” (Note: It based on Flex 2 not 3 ;-) )

    -Jens

  8. Sep Says:

    Thanks for that, its very helpful. I am glad you told me about the pureMVC at FOTB07. I am from Australia and we were at the same table in the Casino ;)

  9. sectore Says:

    @Sep: Hey Brett, I remember our talk at FOTB07. It’s nice to meet you here again :-) BTW: Few weeks ago I noticed your new blog – keep on blogging ;-)

    -Jens

  10. Tutorials | PureMVC Roundup « Flash Enabled Blog Says:

    [...] A basic PureMVC MultiCore AS3 example using Pipes Utility and Modules [...]

  11. mani Says:

    Thank you very much ,sectore^_^

    Your demo is simple and wonderful!

    But when I goto the link [“Understanding PureMVC Pipes” by Joshua Ostrom. Great tutorial!], which have a demo like you, but it make me confused@_@, I can’t found its lib from the source of it, so do you have that?
    I just found other demo of that at http://dluminosity.com/demos/modules/MortgageApp.html, but this doesn’t use pipes, and the lib is not the same as the first.

    So, please give me some suggestion about that
    Thanks for your time!
    mani.

  12. sectore Says:

    mani, thanks for your feedback! I’m glad to see that the “HelloPipes” sample helps you.

    P.S.: Please get in contact with Joshua for getting the full source of his example – I’m sure that he will help you ;-)

    -Jens

  13. Chris Says:

    When I try to import with Flex Builder 3 I get:

    “Not a valid archived project. If the zip was not created via Export Flex Project, use Import > General > Existing Projects into Workspace.”

    Doesn’t look like the archive has all of the project files in it. I can still import it into an existing Flex project but would be good to have the exact project.

  14. Alain Duchesneau Says:

    Hi sectore!

    I’m very happy to find this tutorial. I’m currently building a Flex/PureMVC_multiCore and it’s like scramble eggs in my head.
    I’m building a very complex program (at least for me I guess…) and I’m not happy with the structure I come up with.
    I like very much yours. So much I started to refactor my project based on your code.
    I have a question: When I load modules, I need to send messages to the shell as quickly as possible (my modules act like plugins to the shell to, adding some functionnalities). I tried to put
    sendNotification( ApplicationFacade.SEND_MESSAGE_TO_SHELL, “Module onRegister” );
    inside the onRegister() of my module’s mediator but nothing happens.
    Where is the best place I should place theses initialization messages so they get fired as soon as possible?

    thanks for your work!

  15. sectore Says:

    Alian,

    to send messages from module to shell all needed pipes have to be registered and connected. The ShellJunctionMediator starts this process after receiving a FlexEvent.INITIALIZE from the module calling its method named connectModule(). During this process the SimpleModule will be informed to accept an output- and input-pipe calling its methods acceptInputPipe() and acceptOutputPipe() from shell to register pipes or to add pipeListener as well.

    Anyway, to simplify to handle the result of all these things just wait until the Module has fired it’s FlexEvent.CREATION_COMPLETE. After that a module may send a first message to its shell as soon as possible ;)

    -Jens

  16. Newtriks Flex + Flash Development » Blog Archive » Garbage Collection in a MultiCore Modular Pipes Application Says:

    [...] examples, feedback and guidance which is a must read for getting a grasp on MultiCore so check Jens Krause and Joshua Ostrom. Jens props for your tip on the definition of a clean up method in the [...]

  17. Sep Says:

    Hey Sectore,

    Its a bit off topic but I remember our conversation at the FOTB07 about flex builder and you told me you were using some shortcuts to generate the getter/setter and all other kinds of cool stuff to improve the coding speed. Could you share this, and how you set it up in a post or just point me in the right direction ? I have been trying today to do it but I feel a bit confused.

  18. PureMVC Multicore « The Algorithmist Says:

    [...] HelloPipes tutorial using MultiCore and Flex Modules. [...]

  19. Chetan Sachdev Says:

    Really cool…
    I have implemented one for myself, I will give it a try, surely I will get more clear picture of Shell/Module concept now ;)

    Thanks

  20. Sam Says:

    hi,
    Can i load swf and use the function? like DLL.Thank

  21. Arindam Biswas Says:

    Just came back here to mention that six months back when i was taking my first steps in learning PureMVC + Pipes, i found this example invaluable!

    A friend and colleague was looking out for similar content and this it it.

  22. Lorenzo Says:

    Hi, very cool tutorial!!

    How can i achieve the communication between modules?Can you explain the right way to do it?

    Thanks in advance

    Regards
    Lorenzo

  23. Anandh Says:

    Great Thanks.
    Could someone suggest how to split this smaple to different project for the Shell , Modules and common class for constants [RSL].
    I tried but really got frustrated while loading the module to the shell. In the Module mediator im getting null expection error message on this call “acceptOutputPipe”.
    Thanks,
    Anandh

  24. Steve Says:

    Hey Jens – just wanted to say that this demo contains it all for getting started with Pipes – brilliant and thanks very much – I really couldn’t have got there without this.
    My one question is this – why do you maintain a reference to the Module’s ApplicationFacade in the mxml file when surely the place to fire off notifications is in the SimpleModuleMediator – isn’t the mxml file simply a view which kicks off pureMVC in the initializeHandler? Wouldn’t it be better to fire off Flash events which are listened to by the SimpleModuleMediator and do the pureMVC notifications from there?

  25. WS-Blog » A basic PureMVC MultiCore AS3 example using Pipes Utility and Modules « Geirr Winnem's Blog Says:

    [...] i learned from: pureMVC Multicore pipes: Jens Krause’s Blog 10 tips for working with pureMvc WS-Blog » A basic PureMVC MultiCore AS3 example using Pipes Utility and Modules. Frédéric Saunier’s Blog Flash only «Modules with PureMVC pipes» [...]

  26. Blog of Ruy Adorno » Archive » Links about Multicore PureMVC Pipes Says:

    [...] Simple tutorial of Pipes integration with code source avaiable [...]

Leave a Reply

Follow sectore on Twitter