Ted Patrick > { Events & Community } > Adobe Systems


Gone Morphic...

Morphic is a GUI framework within Squeak and Self. Morphic replaced MVC (Model, View, Controller) in Squeak due to its many advantages but mostly because of its simplicity in concept and implementation. Here is a brief summary of Morphic...

The Morphic framework is composed of Morphs. A Morph is a graphic object that contains graphical assets, properties, methods and events. A Morph can also contain other Morphs in a nested structure to allow construction of simple to advanced components. Morphic framework provides a default set of events to all morphs in the system allowing morphs to interact with the system or the end user(s). One simply drags a Morph to screen and writes event handlers within the Morph to capture interaction.

Sure sounds like MovieClips to me.

Interesting links:

http://minnow.cc.gatech.edu/squeak/30
http://www.squeak.org/tutorials/morphic-tutorial-1.html
http://research.sun.com/research/self/papers/self4.0UserInterface.html
http://www.cc.gatech.edu/fac/mark.guzdial/squeak/startingmorphic.html
http://research.sun.com/research/self/release/Self-4.0/Tutorial/

PSDK.....

One technique similar to Morphic in PSDK is the use a global event controller. This controller is found in PSDK.EventMonster and provides an extended set of events to movieClips. Essentially, EventMonster listens to user input and detects events of importance. The controller then provides these events directly or indirectly to movieClips or to other listeners.

The original goal was to remove redundant code from within MovieClips/Buttons and allow the developer to use a rich event model. Although this is enhanced in F6 with onX callbacks, these are very generic and need to be refined further. Here is an example:

onMouseUp = function(){}
// whenever the mouse state changes to up

vs.

onTargetMouseUp = function(){}
// whenever the mouse state changes to up over a movieClip

Once the concept of MovieClip target is added, the developer can add callbacks to specific MovieClips to provide interactivity. This is especially powerful combined with the use of the 'this' keyword as the callback function become portable and provide generic behavior to a movieclip while maintaining a single function instance. Here is a sample:

--------------------------------------------------------------------

// import the PSDK library
loadMovieNum ("PSDK/15/core.swf", 1000)

// load eventMonster Library
PSDKimport = {eventmonster:true}

// function used to color objects
colorClip = function (dropee) {
var dc = new Color(dropee)
dc = dc.getTransform()
var dt = new Color(this)
dt.setTransform(dc)
}

//add instances of colorme to the ondragdrop
b0.onTargetDragDrop = colorClip
b1.onTargetDragDrop = colorClip
b2.onTargetDragDrop = colorClip

--------------------------------------------------------------------
Download


Basically, if you drag any movieClip on the b0, b1, b2 movieClips, they will change colors. The magic is in the onTargetDragDrop event handler. When you mouseDown on a movieClip, drag to another MovieClip, and release, PSDK calls an event on both the draggee and droppee targets. The droppee (the one dropped on) received onTargetDragDrop(dragee) along with a reference to the dragee as an argument. The method simply switches the colors. Powerful ehh.

My theory is that if your events are fine grained enough, it reduces function complexity by avoiding filtering generic events. Essentially by moving event logic to the framework, you simplify your application and reduce errors involved in hand rolling custom events. It also frees you from the publish subscribe issues and allows you to act directly vs indirectly.

In Morphic, the framework provides a rich set of events from which to build, thus simplifying the developer interface and avoiding the publish subscribe methodology of MVC. Although this doesn't exclude MVC being used, it simplifies use in most cases.

Enjoy the samples.

Cheers,

Ted ;)






0 Responses to “ Gone Morphic... ”

Post a Comment



© 2008 Ted On Flash

Technorati Profile