|
|
Show Posts
|
Pages: [1]
|
1
|
PureMVC Manifold / Standard Version / Re: Resgister multiple views with a single Mediator
|
on: June 18, 2011, 04:21:01
|
1000 apologies!!!! There was a typo in my code above. The following works: (within the case statement) var index:Number= body.valueOf() if (!facade.hasMediator(SectionViewMediator.NAME+"_"+index)) { facade.registerMediator( new SectionViewMediator(index, viewComponent ) ); }
if the return is "true", I build a new mediator/view, if "false", I will show the already created view. I can only hope my shenanigans here have helped someone else...
|
|
|
2
|
PureMVC Manifold / Standard Version / Re: Resgister multiple views with a single Mediator
|
on: June 18, 2011, 03:43:25
|
Sorry for the "run-on" nature of this inquiry. But I've sort of managed to get some of this working, only I can't seem to retrieve/check for the mediator name when I try to assign an index to it. Since my goal is to have several mediator/view instances of my basic view class, I want to check to see if an instance has been created before instantiating a new one. If a mediator/view instance pair has been created, I just want to "show" it (and hide any others), not re-create it or re-load it's images, etc.
Here's what I'm doing to create a "unique" mediator/view pairing:
in my application mediator I pick up a notification to either show an already created view or create a new mediator/view by executing the following:
facade.registerMediator( new SectionViewMediator(body.valueOf(), viewComponent ) );
in the SectionViewMediator:
The constructor is:
private var sectionView:SectionView; private var index:Number; private var section:Object; // Initialization: public function SectionViewMediator(_index:Number, viewComponent:Object=null) { index = _index; super( NAME+"_"+index, viewComponent); trace ("NAME = "+NAME); }
followed immediatley by:
override public function onRegister():void { trace ("SectionViewMediator Registered"); section = proxy.setSection(index); //section is a valueObject created in the proxy, stored in an array of valueObjects sectionView = new SectionView(); sectionView.init(section);
This seems to be creating the appropriate mediator/view instances - passing a valueObject to the view -, but I haven't figured out how to query the facade to "verify" them.
I've tried using "facade.hasMediator(SectionViewMediator.NAME)", but I don't seem to be able to substitute 'NAME+"_"index' in place of NAME to test whether it's been created/instantiated. The query always returns "false", so I'm guessing my new mediator was created, but it doesn't provide a way to check for the specific mediator/view before "deciding" to create a new mediator/view.
|
|
|
3
|
PureMVC Manifold / Standard Version / Re: Resgister multiple views with a single Mediator
|
on: June 18, 2011, 01:24:40
|
You can have 10 instances of the same Mediator registered, each with a separate view component, but you must give the mediator a unique name when you construct it.
So instead of:
public function ViewProgressMediator( viewComponent:LoaderSprite ) { super(NAME, viewComponent); } You'd do something like this:
public function ViewProgressMediator( viewComponent:LoaderSprite ) { super(NAME+"/"+viewComponent.id, viewComponent); } -=Cliff>
I'm still struggling a bit with this: where does 'viewComponent.id' come from? Does this assume the component is instantiated before this mediator and you're somehow passing the .id value with the (viewComponent:LoaderSprite)? Can I give/pass the id to the mediator to use in its contstructor AND to creates its View? Like: private var index:String;
public function SectionViewMediator(viewComponent:Object=null, id:String) { index=id; super( NAME+"_"+index, viewComponent); } and then override public function onRegister():void { sectionView = new SectionView(); sectionView.init( index ); }
|
|
|
4
|
PureMVC Manifold / Standard Version / Re: Resgister multiple views with a single Mediator
|
on: June 11, 2011, 01:18:01
|
I think I understood much of that. In any of these scenarios, would it be advantageous to create a vo for each view/component instance? I'm thinking a dataProxy could parse an xml that contained things like titles, copy and paths to images for each view component and assign/store each component's particular data in a corresponding vo, then have a data array hold each vo in the appropriate index/id. When instantiating the mediator/component I could pass the data[id] of the vo. And from then on call a show/hide type function to the already created view mediator/component by its id. Or am I adding an unecessary step or not understanding the vo concept correctly?
The upshot of all this is to avoid recreating a view once a user has called for it, since each view loads a set of images that shouldn't be re-loaded/refreshed with every call; just checked to see if it/they have already been created/loaded, then show or create as needed.
something like: for ( var i:uint=0; i<sections.length(); i++ ) { var section:XML = sections[ i ]; var id:String = section.@id; var vo:SectionVO = new SectionVO( id, section.@label, section.content,
section.imagePath ); data[ id ] = vo;) }
|
|
|
5
|
PureMVC Manifold / Standard Version / Re: Resgister multiple views with a single Mediator
|
on: June 10, 2011, 02:53:26
|
How do you assign an "id" to a viewComponent instance? In the sample codes I've looked at for view component, the NAME is declared like "public static const NAME:String ='ViewComponentName'." I would be getting the number of views needed from the data source and therefore would need to assign "id" dynamicaly for each required instantiation. Would I declare an "ID" constant and give it a value of something like NAME+'id'? ANd then how would I pass that id to the instantiation? (yes I'm a newbie)
|
|
|
|
|