Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Multiple applications with the same core [flash]  (Read 10522 times)
BobC
Newbie
*
Posts: 4


View Profile Email
« on: April 23, 2009, 08:14:17 »

Hi,

This is probably a very simple question but is has me stumped for a while now.

I'm building several sites with Flash CS4 with the same core taking care of loading, navigation, interface logic, etc. Mostly the visual elements (components) will be different with perhaps a few changes to the mediators.

Of course I want the custom code for each project to be as little as possible but I have trouble figuring out how to approach this. If I uses custom classes somewhere in the application they have to be imported making the importing class custom as well, etc.

What I would like to do is have the base class that is defined in the FLA be different for each application. This class would define it's own AbstractFactory which later on in the application creates the required components and mediators.

This way I can keep the ApplicationFacade, startup logic, proxies, etc identical for each application.

So that's the theory. But I can't figure out how to make it work :-(

Any help would be much appreciated.

Bob

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: April 23, 2009, 09:25:09 »

I'm guessing the Document Class defined for your app would come into play here.

-=Cliff>
Logged
BobC
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: April 23, 2009, 09:49:14 »

Thanks for your reply.

Using a different document class for each is what I had in mind. But I can't figure out a reliable way to use that as a basis to create different components and mediators without having to change the surrounding classes as well.

Right now I have the following:

SiteEntry (Document Class)
ApplicationFacade
- StartupCommand creates a StageMediator
StageMediator creates the SiteMediator which in turn creates the other view components and mediators.

SiteMediator is the one that needs to be adapted for each application but I would like handle the changes from SiteEntry. Without having a different ApplicationFacade, StartupCommand, etc.

Bob
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: April 23, 2009, 11:38:04 »

You could, in your document class, instantiate the SiteMediator class, passing in the ref to the stage, then pass it to your ApplicationFacade startup method. Have startup pass this to the startup command to be registered along with everything else. So you've just moved the responsibiliy for creating the unique mediator out of thr startup command and into the document class.

-=Cliff>   
Logged
BobC
Newbie
*
Posts: 4


View Profile Email
« Reply #4 on: April 23, 2009, 11:49:29 »

Thanks.

I have gotten something a bit similar working but your solution is more elegant. I'll give it a try. Thanks again.

regards,

Bob
Logged
akastar
Newbie
*
Posts: 4


View Profile Email
« Reply #5 on: May 13, 2009, 05:12:35 »

I am also having a very similar issue, I have only just be assigned the task to alter a game I have created with the pureMVC framework, a future project so my head isn't completely in it yet but I'm starting to investigate the correct approach to reuse as much as possible.

The initial problem is that most of my classes use the import statement and Class.NAME which seems to bind that class to certain other classes like commands to Proxies or components to the data list - however the new game differs slightly on the proxy, once I start altering it to a and reshuffle it into a separate new proxy I get this cascading effect where other classes now need this modified reference and so a new import statement is needed and that ripples again, obviously not very reusable. Perhaps my setup is incorrect? or I need to keep the same proxy but work out a more general approach to handle the two types or consider using an interface when I do the type casting?

Any initial help on the right approach to consider when reusing code will save me many hours in the future.

Many Thanks,

David.
Logged
BobC
Newbie
*
Posts: 4


View Profile Email
« Reply #6 on: May 13, 2009, 11:40:10 »

Hi,

This is the solution I settled on and I think it would work for you as well. It might not be the simplest but so far it works for me :-)

The key is using interfaces instead of classes in some places. This makes it possible to change the actual class without having to change the import statement (which would create a cascading effect).

So how I have gotten it to work:

Instead of directly creating components, mediators and proxies in classes, I create them through a ComponentFactory. This component factory is different for each version of the application and returns an instance of a mediator or something else.

Some code to clarify:

In the document class I have this:

:
import interfaces.IComponentFactory;
import ComponentFactory; // the component factory for this specific application

public function startApplication():void
{
facade = ApplicationFacade.getInstance();
facade.startup( this.stage, new ComponentFactory() ); // the component factory is send along
}

In the facade I store a reference to the factory so every other class can reference it

:
public function startup( stage:Object, factoryReference:IComponentFactory):void
{
factory = factoryReference;
}

Now if an mediator would like to create new mediators it would do something like the following. For you it would create a proxy.

:
import IComponentFactory;
import IMediatorPlus;

private function initializeSite():void
{
private var factory:IComponentFactory = ApplicationFacade.getInstance().factory;
site = factory.createSite() as MovieClip;
var siteMediator:IMediatorPlus = factory.createSiteMediator(site);
facade.registerMediator(siteMediator);
stage.addChild(site);
siteMediator.init();
}

So what happens in the component factory? Well, nothing much but since it's contents are 'hidden' by using a proxy it is easy to use a different component factory that creates different components without have to change any mediators or such that reference it.

:
public class ComponentFactory implements IComponentFactory
{

public function createSite():IBasicComponent
{
return new Site();
}

public function createSiteMediator( component:Object ):IMediatorPlus
{
return new SiteMediator(component);
}

}

As I said it might not be the simplest or best solution so if anybody has ideas on how it could be improved please post them.

Bob
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: May 14, 2009, 05:29:23 »

This looks like a perfectly reasonable approach.

-=Cliff>
Logged
akastar
Newbie
*
Posts: 4


View Profile Email
« Reply #8 on: May 14, 2009, 06:51:43 »

Thanks bob that sounds very helpful :) I can see it working so I will begin with that implementation and see if any other suggestions come around for the easiest solution.
Logged
Pages: [1]
Print