Archive for category PureMVC

PureMVC Skeleton for ActionScript projects

I had previously done a PureMVC skeleton for Flash websites and applications, meaning that you would use the Flash IDE compiler to compile your project. Lately I have been doing more and more ActionScript projects (compiled using the Flex compiler but not using the Flex framework) because it permits the separation of big FLAs into smaller ones thus facilitating working in team. But I had no template/skeleton to start with until now.

So here it is:

PureMVC ActionScript Project Skeleton

It still uses an external preloader and I added a local Boolean so that the application knows your are testing locally and not on the sever (useful when making server call). One of the major change is the inclusion of the SharedAssetLibrary. Basically this emulate having one FLA with all graphics and MovieClip, but you actually can have multiple FLAs. When you want to add something to the SharedAssetLibrary you first add it to a FLA, set it to Export for ActionScript and then compile it to the swf folder. Then you can add it in the SharedAssetLibrary using the embed statment:

//BackgroundAsset being the name you gave it in the library
 
[Embed(source="../../../swf/Background.swf", symbol="BackgroundAssets")]
public var BackgroundAssets:Class;

Now if you want to use this in any of your views, first import SharedAssetLibrary and than you can use it like this:

var BackgroundAssets:Class = SharedAssetsLibrary.getInstance().getAsset("BackgroundAssets");
var assets:* = new BackgroundAssets();
addChild(Sprite(assets));

I included a FlashDevelop project file in there, but you can just delete it if you use Flash Builder.

Using a skeleton greatly reduce the setup time of a project, so I hope this will help you. I want to look into doing a skeleton for Flex Application, because I don’t like the skeleton that is available on the PureMVC website.

, , , ,

7 Comments


How to handle Stage resizes with PureMVC

I am starting to like the Proxies a lot in PureMVC because I am always creating new ones (Google Analytics Proxy, SWFAddress Proxy, etc) and they are reusable from project to project.

The latest one is a Proxy that keeps track of the resizing of the stage. I found it was a nice way to handle the problem where you set the stage to NOSCALE and you want to handle the resizing yourself. In those situation you would have multiple views/elements reacting differently + you would have to manage adding and removing listener to the stage. Now with one Proxy setting one listener to the stage and sending notifications whenever it resizes, I found it was simpler. Here is the code for my Proxy:

package com.zedia.model{
  import com.zedia.ApplicationFacade;
  import flash.display.Stage;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import org.puremvc.as3.interfaces.IProxy;
  import org.puremvc.as3.patterns.proxy.Proxy;
/**
* Model for the everything that is related to Resizing.
*
*/
  public class ResizeProxy extends Proxy implements IProxy{
    public static const NAME:String = "ResizeProxy";
    private var _stage:Stage;
    public function ResizeProxy(newStage:Stage){
      super(NAME);
      _stage = newStage;
      _stage.addEventListener(Event.RESIZE, _onStageResize, false, 0, true);
    }
 
    public function get stageWidth():Number {
      return _stage.stageWidth;
    }
 
    public function get stageHeight():Number {
      return _stage.stageHeight;
    }
 
    private function _onStageResize(event:Event):void {
      facade.sendNotification(ApplicationFacade.STAGE_RESIZE);
    }
  }
}

Now in the StartupCommand of your application you register the Proxy and pass it an instance of the stage. It is easy to do so because you already have to pass one instance of the stage to the ApplicationMediator. Once that is done, your Proxy is running and sending the notifications. All that is left is to listen and to handle the notifications in the Mediators of the views that needs to react to the resizing; as simple as that.

, ,

10 Comments


PureMVC Skeleton for Flash Applications / Websites

I have done a couple of site using PureMVC and Flash and it seems that at the beginning of a project I’m always doing the same things, creating the ApplicationFacade, the folder structure, the main fla, etc. I thought it might be useful to slap together a generic skeleton for a PureMVC Flash application or website. You can download it here:

PureMVC Flash skeleton

All you have to do is in the src/com folder, rename the folder PROJECT_NAME to your project, and do a find and replace in files for PROJECT_NAME to replace it with what you changed the forlder name to. I didn’t include the PureMVC library in there because I suggest fetching the files from the official PureMVC website so that you always get the latest version. Once you get them, put them in the lib folder and you should be able to compile.

The rar file contains the following:

  • Main.fla, Preload.fla
  • Main.as
  • ApplicationFacade.as
  • StartupCommand.as
  • ApplicationDataProxy.as
  • ApplicationMediator.as
  • IMain.as (Interface so that the preloader can use the init function of Main.as)
  • the folder structure

This should help save half an hour every new PureMVC project.

, ,

4 Comments


The PureMVC presentation video is live

The presentation I did the other day is now live and I am quite happy with the results. Well I sound like a robot( I guess nobody likes hearing is own voice) and some of the technical limitations (no webcam, audio delay, not having control of my slides) have impaired my performance, but for a first public speech, I’m pretty happy with it.

Also, as a note to myself, next time I do something like this I will inform myself better on which audience I will present to; I think the audience present at the time of the conference had already a good knowledge of the PureMVC framework and my presentation might have been a bit too light. I hope it serves greater purpose as a video than as the live thing.

Here it is; I start speaking at 16:00.

The PureMVC Pirate Internet Radio Conference Takeover

, ,

4 Comments


Myself in the PureMVC Pirate Internet Radio Conference

That is right, in a bit more than 6 hours, if you head to this address:

http://connectpro78922856.acrobat.com/pirate/

you will see me present some of the work I did on the two Home Depot projects we had at Twist Image. I’ll mostly be exposing how using a framework like PureMVC can change how you think and develop an application or website and why we came to choose this particular framework.

I am very excited about this opportunity and I am a bit stressed out at the same time. It’s been a long time since I did a presentation ( back while I was in school) and this is a bit different since I’ll be broadcasting from my desk using a webcam; it will be weird presenting while sat down but I think I’ll do fairly good.

Lastly, I’ve been watching a lot of the TV show The Wire so I hope I don’t slip too much slang words in there.

So again if you want to watch it its tomorrow November 19th at 12h30 (3h30 PST)

http://connectpro78922856.acrobat.com/pirate/

, , , ,

2 Comments


Show your support for PureMVC; Donate a click!

If you use PureMVC and you like it I suggest you head to insideRIA and vote for it on this week poll. I have multiple reasons to ask you to do this.

First off I think it’s a great project and it deserves the attention. More attention means more people might start using it and might get involved which can only be good for the project.

Also, we started using PureMVC on 3 different projects (one being HomeDepot – redefining floors) and I use it in a personal project and I really like it. I developed some skills with it and if PureMVC does well, those skills are going to be more valuable. Also, the people at my jobs might not be so happy if in the near future PureMVC would just crumble (which I don’t think could happen), I would have made them invest expertise in something that would have been shortermed.

Lastly, PureMVC is one off the few framework that support both Flash or Flex based project and that is really important for me; so go ahead, give PureMVC some love.

, , , , ,

No Comments