Oh yeah
<JuiceMaker id="myJuiceMaker" decorator="{JuiceMaster}" click="
myJuiceMaker.makeJuice('orange')" />
is supposed to be;
<JuiceMaker id="myJuiceMaker" makerClass="{JuiceMaster}" click="
myJuiceMaker.makeJuice('orange')" />
On 9/12/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> You can't decorate a UIComponent since it is a DisplayObject and needs to
> be added to the display list.
>
> You have to either us composition or subclass Button and use an interface
> and pass the class to decorate the Button with.
>
> <JuiceMaker id="myJuiceMaker" decorator="{JuiceMaster}" click="
> myJuiceMaker.makeJuice('orange')" />
>
>
> class JuiceMaster
> implemented IJuiceMaker
> {
> public function makeJuice(type:String):void
> {
> trace("Happily making", type, "juice!", "Tralalala!");
> }
> }
>
> public class JuiceMaker
> extends Button
> implemented IJuiceMaker
> {
>
> private var _makerClass:Class;
> private var makerImpl:IJuiceMaster;
>
> public function set makerClass(value:Class):void
> {
> _makerClass = value;
> makerImpl = new _makerClass();
> }
>
> public function set makerClass():Class
> {
> return makerImpl;
> }
>
> public function JuiceMaker()
> {
> super();
> }
>
> public function makeJuice(type:String):void
> {
> if (makerImpl is IJuiceMaker)
> makerImpl.makeJuice(type);
> }
> }
>
>
> public interface IJuiceMaker
> {
> function makeJuice(type:String):void;
> }
>
>
> The above is something that would help what you are trying to achieve with
> display object.
>
> You could also drop the interfaces and use concrete types but hey, if your
> asking about decorators, your asking about design patterns. ;-)
>
> Peace, Mike
>
> On 9/12/07, Claudia Barnal <[EMAIL PROTECTED]> wrote:
> >
> > I believe I might be missing something with the Decorator Pattern.
> > I've tried to get a simple example to work, but I get too mixed up
> > with all the abstracts and what not.
> >
> > Here's what I'm trying to do:
> >
> > Extend a Button and add some functionality to it gotten from another
> > class (non visual). From what I can understand, this is what the
> > Decorator Pattern is for.
> >
> > In pseudo code this is the basic functionality I want:
> >
> > class JuiceMaster
> > {
> > public function makeJuice(type:String):void
> > {
> > trace("Happily making", type, "juice!", "Tralalala!");
> > }
> > }
> >
> > class JuiceMaker extends Button
> > {
> > public function JuiceMaker()
> > {
> > Super();
> > makeJuice("apple");
> > }
> > }
> >
> > And in MXML, I should be able to do something like this:
> >
> > <JuiceMaker id="myJuiceMaker" click="myJuiceMaker.makeJuice('orange')"
> > />
> >
> > Of course this example isn't going into any detail, and doesn't make
> > much sense, but this is somewhat my need.
> >
> > Any explicit explanation on how to get something like this to work
> > with the Decorator Pattern is greatly appreciated.
> >
> > Thanks!
> >
> >
>
>
>
> --
> Teoti Graphix
> http://www.teotigraphix.com
>
> Blog - Flex2Components
> http://www.flex2components.com
>
> You can find more by solving the problem then by 'asking the question'.
--
Teoti Graphix
http://www.teotigraphix.com
Blog - Flex2Components
http://www.flex2components.com
You can find more by solving the problem then by 'asking the question'.