Ted Patrick > { Events & Community } > Adobe Systems


Momento >>> Persistent Components

What is Momento? Momento is a design pattern that allows an object/component to externalize data providing persistence between instances. This is essential when you want to restore state to an object or component between sessions or sub-session. Ideally, a momento enabled component/object could be instantiated, modified, destroyed, and later restored to the identical state prior to destruction by passing an id.

First question you are asking is: why would you do this? I have been working with a small team of developers on a new product called PowerSDK FLOW. FLOW is runtime development framework for executing XML based applications in the Flash Player. It is based on the PowerSDK Framework and extends our open source prior work. In designing FLOW, we needed to manage state within an application and its components. FLOW loads an XML application definition, loads required components, and then writes components to a movieclip. Using a recursive pattern, these movieclips or "Forms" are overwritten as needed by the application. Overwriting mc's mirrors the development paradigm of keyframes but in this case it is implemented at runtime not at authortime. In overwriting forms, state is lost unless we use momento enabled components.

Momento functionality is confusing, especially given that inheritance and other component features needed to be supported. We decided early on that the best way to get seamless functionality was to insert an momento object between a component/object and its prototype. At first this seems problematic but using the __proto__ property pattern and the super keyword it was relatively painless to transform existing components. Here is a diagram of what we did.



Essentially we create a repository and fill it with component instance data(Momento Objects). Momento objects are just plain old objects with the exception that the component constructor has been executed within their scope. We also decided that separating of a component class and the GUI would be good practice. This allows a developer to create an external component skin and reuse a common class. In this case, component architecture is closer to Ghostwire Components (AKA Sunny Hong) rather than MM FUI although both are functional with momento. You can also use components outside of FLOW with just PowerSDK(18) as follows:

myComponent.load({_class:mTextfield, _url:})

Here is an early version of a FLOW application.



In a FLOW enabled Flash Player simply call:

_level0.myapp.render(flowXML)
//movieclip prototype method

In this application, the textfield in both dialogs shares an id value of "_global.momento.name". The first rendering of this component creates the momento instance and the second reuses the instance to render the textfield to screen.

FLOW is scheduled for release next year as a subscription service (no pricing as of yet). If you have any questions about FLOW or PowerSDK, please don't hesitate to ask me.

If your interested in FLOW, I will be speaking at Macromedia MAX in November on Component-Oriented Development w/MACR Flash (CS302W). Stop by the session to see more on FLOW and other component techniques. It should be allot of fun now that the demos are working with Momento.

Cheers,

ted ;)

0 Responses to “ Momento >>> Persistent Components ”

Post a Comment



© 2008 Ted On Flash