mediatorMap.mapView() not working properly, or is it only possible in Context class?
hello, i am currently working in a project and i have an issue with dynamically loaded files. let me explain my workflow.
computer setup:
- mac os x 10.5.8 - eclipse with flash builder 4 plugin
project setup:
- flash player 9 - robot legs v1.1.1, swift suspenders v1.5.1 - i
have some other embedded swcs and libraries (set as merged into
code) - authoringAssets.swc (set as external) (see a bit more about
this: http://jansensan.net/loading-assets-dynamically-part-2)
the issue:
so what i do, is i make sure that my assets are loaded before i map
a view to a mediator. i do already map some views in the context
startup() function, which work like a charm. the reason why i dont
map all of them there is that some of my assets (custom classes
created in the flash ide) are member variables in my view, and
therefore are not available before the assets are loaded.
i thought i could map a view in a command, but when i then try to
add that view to the contextView, the onRegister function is not
called.
thank you if anyone can direct me to some information about this.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Shaun Smith on 24 Jun, 2010 03:03 PM
The mediatorMap can be used from anywhere - have a look at the source for the MVCS Command to see how it gets injected into command instances:
http://github.com/robotlegs/robotlegs-framework/blob/v1.1.1/src/org...
So, the issue is probably due to something else. Can you provide some more info on how you are mapping and adding these views?
2 Posted by jansensan on 24 Jun, 2010 04:03 PM
yea, well, i guess if explain my flow? here is an overview of my classes: http://jansensan.net/images/dump/robotlegs.gif
here is the startup for my context:
here is the InitApplicationCommand
and here is the AddPagesCommand
so what happens is that if i trace something in the SelectImagePage constructor, it is traced, but if i try to trace something in the SelectImageMediator onRegister(), nothing happens.
3 Posted by myrddin on 24 Jun, 2010 04:25 PM
Hi,
If I understand the problem, asolution is to replace your Class by String in mediatorMap.mapView :
mediatorMap.mapView("swc.libray.viewClass",MediatorClass);
In this case, you load your asset, you add your view and this view is mapped at your Mediator.
4 Posted by myrddin on 24 Jun, 2010 04:30 PM
Sorry...
With this solution, you can map all yours views with your mediators in the Context class without importing your view classes.
Support Staff 5 Posted by Shaun Smith on 24 Jun, 2010 04:31 PM
Thanks for the info. I can't see anything obviously wrong with the code.. looks like it should work.
Try adding
trace(SelectImagePage)
to InitApplicationCommand and AddPagesCommand, and check that both commands are referencing the same class.Support Staff 6 Posted by Shaun Smith on 24 Jun, 2010 04:33 PM
@myrddin: that's definitely another option. Mapping to the fully qualified class name will work, but so should the OP's method (he is excluding the classes from being compiled into the main SWF with some compiler options).
Support Staff 7 Posted by Shaun Smith on 24 Jun, 2010 04:37 PM
Another thing to try: add this to both commands:
And then in the commands execute methods:
8 Posted by jansensan on 24 Jun, 2010 09:32 PM
Thank you for your tips, I will try on monday when I get back at work. I do want to bring some additional details: the view that I am trying to associate to a Mediator is not the one that I created in the Flash IDE
In said Flash IDE, I created Movieclips with visual assets. Let's call them VisualAsset01 and VisualAsset02. In the SelectImagePage class, I then create member variables with those classes:
private var someVar01:VisualAsset01;
private var someVar02:VisualAsset02;
Then in I have an public init() function in the view:
public function init():void
{
}
I call the init() function in the onRegister class of the Mediator, but to no avail.
[Inject] public var view:SelectImagePage
override public function onRegister():void
{
}
Basically, since in Flash Builder 4 I can link to external SWF, it gives me autocomplete, but the actual assets are only loaded at runtime. I could map all views in the context, but that forces me to cast my member variables as MovieClips:
private var someVar01:MovieClip;
private var someVar02:MovieClip;
This then works, but I lose autocomplete, not practical. That is why I want to map my views only when my assets are loaded, so that I do not obtain an error at runtime saying that my classes are missing.
I unfortunately do not have the sources with me now, but as soon as I do (Monday) I'll provide a barebone example, maybe that will guide you to help me?
9 Posted by jansensan on 28 Jun, 2010 08:42 AM
hello all, here i provide an example package of how i worked in this project, so it may help people understand where i may have not worked properly. thanks again
Support Staff 10 Posted by Shaun Smith on 28 Jun, 2010 11:06 PM
You need to map the mediator before you add it to the stage:
Notice that the mediator is mapped after the view component has been added to the stage.
Your
InitApplicationCommand
callsstateModel.state = StateModelState.INITIALIZING;
before mapping the mediator:You should be mapping the mediator before setting the model state:
Which sorts your problem out:
11 Posted by jansensan on 29 Jun, 2010 08:04 AM
whoa! what an overlook on my part! i makes so much sense, but i guess i was not looking at the right place at all. thanks so much for helping me out!
Support Staff 12 Posted by Shaun Smith on 29 Jun, 2010 02:35 PM
No problem, glad you're back on track.
Shaun Smith closed this discussion on 29 Jun, 2010 02:35 PM.