Saturday, July 19, 2008

Using JumpShip inside Flex. A roadmap.

Using JumpShip inside Flex. A roadmap.

All files can be found at: for your convenience the entire JumpShip Framework is also included.

        The JSDataModel and JSControllerBase can be used inside of an mxml document as they are. The only trick to using JumpShip in Flex is in using JSViewBase. 

JSViewBase extends Sprite in order to add the ability to add, remove and manipulate DisplayObject's to itself and have those DisplayObjects be part of the Display List. It extends Sprite as opposed to Flex's UIComponent so that it can be used in both Flash and Flex but this decision adds a small amount of complexity for the Flex developer since You can't attach a Sprite directly to most Flex components because all children of a Flex component must extend UIComponent. 

    There are several ways to get past this small annoyance, however. 

    First of all you should realize that you don't need to add JSViewBase to the the Display List in order to use it. JSViewBase is Just a mediator between your Model / Controller and a group of one or more components. It is meant to handle communication between other pieces of the MVC framework. This allows you to build components which don't have any code that is JumpShip Framework specific and wrap them in a JSViewBase instance which takes care of all of the interaction within JumpShip.

    You can create and use JSViewBase just as if it didn't extent Sprite by creating a new instance but not bothering to attach it to the display list. In this case the only thing you loose is the ability to use add components directly to JSViewBase and have them show up on the display list. Instead you would use JSViewBase to store references to it's components which would sit somewhere on the display list. An example of this is provided along with this post.

    Included is a demo Flex project that uses the JSViewBase as a mediator for the Flex compnents contained in the main application.

    Another way to use JSViewBase would be to wrap the class in a proxy component that extends UIComponent. The JSViewBase proxy would just pass all references straight to the JSViewBase instance and the rest of the JumpShip Framework would not know the difference. An example of a JSViewBase proxy class is provided as part of this post.

    A third solution is just to give up the utility function that JSViewBase provides and simply create a new Flex component that implements IView. Although you would loose some of the nicer things that JSViewBase provides, you may decide that those features aren't particularly useful to you anyway. Or you could implement a subset of the JSViewBase functionality in your new component. But as long as your component implements IView, it is capable of fully participating in the JumpShip Framework. Note that IView doesn't require that your implementation be a DisplayObject at all.

    Most MVC frameworks don't even attempt to provide a standard View implementation because as this article illustrates, it can be tricky to implement a View class flexible enough for everyone to use. But JumpShip attempts to go where other frameworks do not, realizing that there is value to establishing conventions even if those conventions get away on rare occasion. But I hope this article illustrates that what may seem like a barrier, really is no big deal when you understand the broader intentions of the JumpShip Framework.

All files can be found at: for your convenience the entire JumpShip Framework is also included.


Mudit Tuli said...

I was playing around with JumpShip in Flash CS3, just got stuck with views, how to add assets to the Stage ?
Do we add the view(sprite) to the Stage ?
And thanks for a very nice and easy framework.


JumpShip said...

In CS3 the easiest way is to add your Views to the Stage and then add the DisplayObject assets to the Views. But as this article shows, that's just one option.

If you wanted to add the DisplayObjects assets directly to the Stage, for instance, you could just store references to them inside your Views.


mudit said...

I am loading an XML in a Command, want to notify the controller when the XML is loaded and parsed by the Command, for this I am passing the return Function in createCommand().
But loading of data from a server or an external source is an asynchronous process, and onResultOperation() is called from executeOperation(), as a result the return function is called before the XML is loaded.

mudit said...

Does jumpship has a google group, github ?, because comments section of a blogpost is not the best place to have a discussion about a framework.

JumpShip said...

Move the onResultOperation call to a load complete handler for the XML load process. That way the you can return the result of the XML or handle load errors

JumpShip does have a mailing list for general discussion about the framework.