OK, this is helping a lot. And Steven I see what you mean, poor Flair is starting to look a little meager now.

In my app, I have several different states. Each state sets itself up by initializing variables and drawing its various pieces, and the final piece is to subscribe various parts of the app to events that happen in other parts. So in one state I have methods like:

onRoomObjectPress()
onRoomObjectRelease()

that are triggered by onPress and onRelease events in my object movieclips. These onSomething() methods contain the core logic of the app--code to resize clips or process values or what have you. This structure is good because I know where to look to track down where things happen, but its bad because sometimes a bunch of things are supposed to happen at once and those onSomething() methods get hairy.

So in this new mixin strategy (which does look a lot like Strategy, thanks James!), should I design my Snappable class to have methods that would map to movieclip events, such as:

startObjectDrag triggered by     obj_mc.onPress
checkForSnap triggered by setInterval or onEnterFrame type of event, in this case onObjectDrag
stopObjectDrag  triggered by    obj_mc.onRelease

Am I headed in the right direction?

Thank you again, this

OK
DAH

The theory of mixins originated from multiple inheritance programming
languages such as C++.

So for example: Say you wanted to make an object dragable, clickable and
resizable. You would then create separate classes called: Dragable,
Clickable and Resizable (common naming convention for a mixin).

Then your base class would just inherit form those 3 classes.

Since AS2 doesn't support multiple inheritances you can emulate a mixin
using interfaces and composed classes.

For example:

IClickable, IDragable, IResizable

So then your AS2 class would say:

Class MyClass extends Whatever implements IClickable, IDragable, IResizable

Those interfaces just specify what methods your class has to support.

From there you could have a class (or a consolidated class) implement that
functionality

private var clickable:Clickable = new Clickable();
private var dragable:Dragable = new Dragable();
private var resizeable:Resizeable = new Resizeable();

from there you just forward / wire the appropriate methods to its
corresponding instances.

public function startResize()
{
        this.resizeable.startResize();
}

Or for arguments:

public function startResize()
{
        this.resizeable.apply.(this.resizeable.startResize, arguments);
}

You could get even more fancy by externalizing those classes so based on
various rules you could pass in different resize logic, etc.

Anyhow, hope that gets the gears turning. =)

DISCLAIMER: Didn't spell check or test anything in the compiler so maybe
some typos. =)

-erik


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David Ham
Sent: Monday, January 29, 2007 7:12 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Flair Pattern bad mixins good (?)

Anyhow I tend not to use decorators (matter of personal taste). I
prefer to
not Frankenstein an object at runtime and rather use mixins
(composition +
interfaces).

Ah, thank you, now we are getting somewhere!

Tell me about mixins. I have used EventDispatcher before, but I am
unfamiliar with the theory behind mixins in general.

In my app, i have objects that can be dragged around in a Room, and
they have a "snapping" behavior that lets them snap to the walls of
the room, and in some cases, rotate themselves so that a given side
of the object is always to the wall.

Currently, my snapping behavior is in a separate class like the one
at the top of this thread. If the room object has snapping enabled,
the  SnapFlair class adds an object with a bunch of methods and
properties to it. The snapping methods are triggered by an event that
is broadcast as the room object is being dragged.

How would I implement this as a mixin?

Many thanks fellas!

As for Steven, sounds like HE'S got a case of the Mondays! *smirk*

OK
DAH
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

--
David Ham
http://anthropomorphy.org               ::      +1 630 297 1273
http://davidham.com                     ::      [EMAIL PROTECTED]



_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to