Bumpslide App Template
I’ve recently updated my application template located in the examples section of my Bumpslide Library. I’ve taken this a step further by packaging this as an archive that is ready to use as a starting point for new AS3 Flash applications.
Download: Bumpslide AS3 App Template
This project template includes everything you need to get started with my library as an application framework. This is a working application with FLA file and sample HTML including support for deep linking with SWFAdress. The source code for the application is in the ‘app’ package. Reading the documentation in the source files is the best way to learn.
Command Pattern is Optional
I have found that for small applications, the command pattern is often overkill. Since this is a starting point for small flash apps and micro-sites, this application template does not use commands. All state changes are affected by simply changing the data on the model, and logic inside the model setters coupled with bumpslide binding magic results in a rather agile approach to flash application development that is as MVC as you want it to be. That is, if you want to separate your views from the model, feel free to dispatch events, and catch them in a top level view or mediator. If you want to encapsulate all model changes in commands, feel free. There is a cairngorm-like FrontController included here if you want it. Just replace the Controller with a class that sub-classes FrontController, and use the CommandEventDispatcher to dispatch the command events.
If you find this useful, or if you have any issues, please let me know. This is the code I use every day, and it’s constantly evolving.

November 9th, 2008 at 7:43 pm
Thanks for putting this out. Your bindable model has made my actionScript life a much happier one!
November 17th, 2008 at 3:53 am
Great template. Thanks for sharing!
As far as the ui package goes, I was wondering if you would consider removing the tweening code from at least BaseClip, if not all of the ui. This would make the components lighter and not penalize us for using a different tweener….
There could be external static hooks instead, like how you initialized DisplayShortcuts?
November 17th, 2008 at 12:25 pm
@Gil, the tweener stuff is only being used in the fadeIn/fadeOut functions which are in turn used by the hide/show methods of BaseClip. This class has become a place for shortcut methods like that. I agree that in this case, it’s not worth the dependency. Thanks for calling me out on that. For now, that’s pretty easy to comment out, but I do feel your pain, so I’ll move those functions to a static utility elsewhere. I’m not using Tweener anywhere else. FTween, however, is a core piece used in my grid and scroll panels as well as the drag and zoom behaviors. This will still be required.
November 19th, 2008 at 12:04 pm
David! This is awesome. It is cool to see more examples of how you use the code.
I have a question, I thought I would post here so that more people could see… I was looking into grabbing variables from the URL. I came across this:
http://evolve.reintroducing.com/2008/07/03/as3/as3-querystring/
I have been poking around the new App Template and I would like to stay true to the Bumpslide way… What do you use to get the vars from the URL?
November 19th, 2008 at 12:35 pm
@Ben – Yes, you can grab url params via external interface, but this class needs some checks in place for when external interface is not available.
I use SWFObject’s utility functions (swfobject.getQueryParamValue) or PHP to pass query string values to the swf via flashvars (loaderInfo.parameters). In my applications, flashvars are parsed by the Config class, an instance of which is stored in the Model. Then, all run-time settings are in model.config which is created either in a startup command or by the controller directly before the main view is instantiated. The Config class has default settings in place that are applied whenever running the swf in a context where flashvars are not available (ex: ‘Test Movie’). Overall, I think this is a more elegant and flexible approach than relying on ExternalInterface, but I’m sure there are cases where that could be necessary. Thanks for the link.
January 21st, 2009 at 1:42 am
Updated: To followup on the tweening issue, the show/hide methods are no longer included in BaseClip. Thus, there is no longer a tweener dependency. The fadeIn/fadeOut shortcuts are now static methods in com.bumpslide.tween.Fade.
On a similar note, I have added “_autoAlpha” support to FTween, and there are new FTween shortcuts fadeIn, fadeOut that make use of these.
January 21st, 2009 at 2:50 pm
So I am looking at the model. I see that you hard coded Home, News, and Puppies into model.sections and into the const array SECTION_PATH_NAMES. I want to pull that data from an external source.
In previous Bumpslide projects I have called service.loadSiteXML(); in the very beginning of MainView. I guess now I am confused as the best way for the model to get the data in it’s constructor… Or do I even need that?
Here is what I am currently thinking:
1. MainView init call service.loadSiteXML();
2. Main View: bind model.sections
3. service.loadSiteXML: fills the model.sections array with the section headers from the XML file
4. MainView: sections setter calls function to build the rest of the site?
5. Then use model.sections in place of SECTION_PATH_NAMES?
What do you think? What would be the best way to get the section names into the model?
January 21st, 2009 at 3:11 pm
Ben, this sounds like a fine approach. I would recommend doing this at startup before the views are initialized. Assuming you're not using commands, you can do something like this in your Controller's constructor after the service is initialized...
And, comment out that call to notifyComplete. We will then call that inside the onSectionDataLoaded function.
Now your main view initialization (AppRoot.initView) will not be called until the site config XML is loaded.
These days, I'm using the command pattern quite often, and in this case your controller would extend FrontController, and you would have something like this in your Controller's constructor instead of the Service proxy init stuff.
Notice that third param to the CommandEvent. That is an onComplete callback. This concept is borrowed directly from the UniversalMind cairngorm extensions.
I guess it's time to make a new app template that includes commands.
January 22nd, 2009 at 4:41 pm
I just tried your first suggestion. I am getting a Binding Error. Here is my code:
Then I got this error:
[Binding Error] Error #1056: Cannot create property sections on builtin.as$0.MethodClosure.
ReferenceError: Error #1056: Cannot create property sections on builtin.as$0.MethodClosure.
at com.bumpslide.data::Binding/::executeBinding()
at com.bumpslide.data::Binding$iinit()
at com.bumpslide.data::Binding$/create()
at com.bumpslide.data::BindableModel/bind()
at app::Controller$iinit()
at app::AppRoot/app:AppRoot::onAddedToStage()
Any thoughts?
January 23rd, 2009 at 12:45 am
sorry, ben. I messed up. The binding needs to be like this.
And, really, that onSectionDataLoaded handler will be receiving an Array, so you can type the sdata parameter as such. But, I guess you don't really need it here assuming you are updating the model from your service class.
Code sample above has been updated.
February 3rd, 2009 at 5:21 pm
David, I'm finally getting around to trying out your template. One question, from an MVC newbie, I'm going to be integrating a preloader for assets based on XML content. I'm not sure how to fit the preload code into the startup sequence.. it's not exactly a view, but it has display elements. any advice or suggestions?
February 3rd, 2009 at 5:40 pm
Wayne, if it has display elements, it's a view. Think of it like a top level section. Section 0 is asset loader. Section 1 is homepage, etc. Once you have your model and configs initialized, init your MainView and go to section 0. Section 0 should trigger a view where you can do your preloading and whatever you want. Once done, model.section=1. This should then take you to the homepage.
A more robust approach... You could also have a flag in your model like assetsLoaded (boolean). If deep-linking to section 2 and assetsLoaded is false, go to section 0, and save a reference to your deep-linked path (model.requestedSection=2). Then, once assets are loaded, set model.assetsLoaded = true. In your assetsLoaded setter, if assetsLoaded is being set to true and model.requestedSection>1, model.section = model.requestedSection.
The key to command-less MVC is to put logic in those bindable model setters. Have UI events trigger state changes on the model, and let the model sort things out. Model is the new controller.
When this gets messy, start using commands to encapsulate business logic.
February 3rd, 2009 at 6:16 pm
Thanks, that helps a lot.
February 4th, 2009 at 2:39 pm
David, I am using the ImageUtil. I am getting a type error, yet my code and your code looks fine to me...
public function loadPic(url:String):void {
loader.load( new URLRequest( url ), new LoaderContext( true ));
loader.contentLoaderInfo.addEventListener(Event.INIT, onImageLoaded );
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
addChild(loader);
loader.x = 4;
loader.y = 4;
}
private function onImageLoaded(event:Event):void{
ImageUtil.resize(loader, 398, 398, false);
}
error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.bumpslide.util::ImageUtil$/resize()
at app.view::PagePic/app.view:PagePic::draw()
at com.bumpslide.ui::Component/updateNow()
I initialized the loader in the constructor.
Thoughts?
February 5th, 2009 at 2:37 pm
David, sorry to be a bug! one more issue I'm having.. per this suggestion from you:
"Then, once assets are loaded, set model.assetsLoaded = true. In your assetsLoaded setter, if assetsLoaded is being set to true and model.requestedSection>1, model.section = model.requestedSection."
In my assetsLoaded setter I'm doing exactly this, to no avail. The strange thing is if I replace requestedSection with a literal value, (this.section = 2), it works. But trying to assign it to a variable value (this.section = this.requestedSection) doesn't work, even though the value will trace correctly.
Any ideas on this?
February 5th, 2009 at 11:56 pm
Ben, the problem here is that you're trying to resize the loader before it's loaded. Ok, the real problem is that when resizing a loader, the resize method resizes loader.content. The null reference error is coming when loader.content is null. I should put a check in there for that. Meanwhile, in your draw method, make sure the loader is loaded.
February 5th, 2009 at 11:59 pm
Wayne, note that binding events don't fire unless the value actually changes. Beyond that, I'd have to see code.
March 28th, 2009 at 11:34 am
cheers david!
big thank u for the bumpslide library and the app template :)
having a pureMVC background (always trying to use the appropriate
approach for each project) i have to say your library is really cool ;)
the things you mentioned regarding the command pattern sound
interesting... would really appreciate an additional app template that
uses commands to see how you implement the command pattern.
keep up the good work!!