Hi,
I've been following this tutorial:
http://www.as3dp.com/2009/04/26/acti...esign-pattern/
And so far everything is working. However, I want my Concrete class to load in an item from the library (basically the graphic for that item). This works fine when just loading in the Concrete class, but as soon as I add a decorator the graphic disappears, and I'm not sure why.
The code so far is:
My Abstract Class
Abstract DecoratorCode:package todd.flashBook.navigation{ import flash.display.MovieClip; public class navButton extends MovieClip{ public function navButton():void{ trace("Nav button Created"); } } }
Concrete ClassCode:package todd.flashBook.navigation{ public class navButtonDecorator extends navButton{ protected var button:navButton; } }
Concrete DecoratorCode:package todd.flashBook.navigation{ public class prevButton extends navButton{ public function prevButton():void{ trace("I am a previous button"); } } }
Everything works, I can call functions from each, just the graphic goes.Code:package todd.flashBook.navigation{ public class pageSkipDecorator extends navButtonDecorator{ public function pageSkipDecorator(buttonRef:navButton){ this.button = buttonRef; } public function skipToPage(pageNum:Number){ trace("skipping to page"); } } }
I'm calling the Class like this:
I'm pretty sure I understand how the Decorator pattern works (bar the reference to the component in the decorator abstract class), but I'm not sure why the graphic isn't showing. I get no errors either. This seems like a usefl pattern, and I can already think of ways I can use it in future projects, but not without this stumbling blockCode:var button = new pageSkipDecorator(new prevButton());
Cheers if anyone can shed some light!





Reply With Quote