Changing views, resize signal, and performance

Christen's Avatar

Christen

22 Jun, 2011 08:46 AM

Hi

I am making my first robotlegs/signals/Flex project, and I was wondering how you change views.

IE:. So view 1 is user settings, view 2 is news

If I want to change from view1 to view2 what would be a good way of dooing it?
Signala view menu hits a controller ,that does what?
Use state or addElement.
I would also like to make sure that view2 is setup fully before showing it as well.


Second question:
I would like to tell all views that there has been a stage RESIZE Event and what the new stageWidth and stageHeight is. So the views (mediators) can resize.
Signal to controller controller to.?? Or all views have a reference to the main Application class (is there a shortcut here to get a refrence to the main app class) and listen to the event?


I was wondering about performance. I read the article from Joel Hooks http://www.developria.com/2010/06/an-introduction-to-robotlegs-a.html He states: It is worth noting that in graphics intensive applications with many display objects (1000s), this automatic mediation can be a performance issue. I am making a strategy game, where I am going to have a lot of sprites going arround. Is it going to be a problem? Is it only if they are injected, or just f they are added to stage? Because I was tinking that I would have one class that controlls all the units, so I dont call them directly.

  1. 1 Posted by neilmanuell on 22 Jun, 2011 09:02 AM

    neilmanuell's Avatar

    Re performance question. That is regarding automatic mediation. Ie, if you wanted all your sprite to be magically mediated and de mediated when added / removed from view. But you wouldn't do that, would you :)

  2. 2 Posted by Christen on 23 Jun, 2011 08:30 AM

    Christen's Avatar

    I have another question.

    Where do you put the sound? In views? I have a more general soundlib class that handels most of the sound functions. Where to put it? (I know that there is no right answer, but what would you do?)

    By the way, the other questions in my original post, anybody?

  3. Support Staff 3 Posted by creynders on 23 Jun, 2011 08:44 AM

    creynders's Avatar

    1/ I'd use flex states to switch between views and since that's pure view logic there's no need to involve any controller like classes for that.
    Then, regarding having view2 setup fully before showing, you could simply hide view2 as long as the data it needs is being retrieved and then show it when all data is loaded.

    2/ there's again no need to involve the framework for the resize event, since all display objects can listen to the stage resize event directly. That would only be necessary if some kind of calculation needs to be made based on the stage dimensions AND that result would be needed by various views.

    3/ regarding sound: that's pure view logic as well

  4. 4 Posted by Christen on 23 Jun, 2011 08:57 AM

    Christen's Avatar

    1/ But what if I dont want the code to run before I want to use the view?

    2/ But if the view is not added (not using states) to stage yet it can not listen to it, and I want to give the dimentions before I add it so that it can setup before beeing shown to the users. I also just wondered it I want to send a general signal out to all views about resize, pause, updat, error, whatever. What would be a good way of dooing it?

    3/ Ok

  5. 5 Posted by neilmanuell on 23 Jun, 2011 09:02 AM

    neilmanuell's Avatar

    Re sounds, I think it depends on the use of sound.

    If its streaming, keep it external and have a model of urls.

    Personally I would embed my sounds in a SoundLibrary class. And again it depends on how they are used to how I would have them accessed.

    Sound is not always view, is the music of an mp3 player view? I would say in that case it is part of what is being modeled.

    I think that IS down to personal choice and the use case you are.implementing.

  6. 6 Posted by Christen on 23 Jun, 2011 09:25 AM

    Christen's Avatar

    Yes, I think sound can be a mix.
    I would guess that I have my sounds paths in a model, the files in an external assets folder, and the calling of the sound in views, but the handling of the sounds? Maybe in a controller (or view helper file)?

    In the sound handler I check if the sound is downloaded, if the sound is muted. And play it if it is. Also if it is a looping sound and it is set to play but is not downloade yet it will begin when it is fully downloaded. This is the logic I don't know where to put?

  7. 7 Posted by neil on 23 Jun, 2011 10:07 AM

    neil's Avatar

    I gotta be honest, games is not my thing, so I don't feel I can give you high performance related advice... so I'd best duck out :)

  8. 8 Posted by Christen on 23 Jun, 2011 10:34 AM

    Christen's Avatar

    Ok thanks.

    How about changing views. I havent found any good exampels of how to do it. It is two totaly different views. The normal exampels I have seen ussualy is one "page", where elements come and go. But I want to change the whole "page" whith another.

    And is there a good way of sending an event or signal to all the active views? All the views listen to some sigelton class maybe? Or someway to make a contoller call all the views?

  9. Support Staff 9 Posted by creynders on 23 Jun, 2011 01:49 PM

    creynders's Avatar

    1/ But what if I dont want the code to run before I want to use the view?

    What code are you talking about? The code to retrieve the data shown in the view?
    If that is the case you can let the mediator dispatch a RetrieveSpecificDataSignal which is mapped to a command that retrieves the data.

    2/ But if the view is not added (not using states) to stage yet it can not listen to it, and I want to give the dimentions before I add it so that it can setup before beeing shown to the users. I also just wondered it I want to send a general signal out to all views about resize, pause, updat, error, whatever. What would be a good way of dooing it?

    The containing class can pass the dimensions to the view when instantiating it.

    Obviously if you have several views that need to listen to the same signal, you can mediate all of them and let their mediators pass the signal to them. I'm not saying you should never let views communicate through the framework, I'm just pointing out that in most cases it's unnecessary.

    How about changing views. I havent found any good exampels of how to do it. It is two totaly different views. The normal exampels I have seen ussualy is one "page", where elements come and go. But I want to change the whole "page" whith another.

    As I said that's perfectly doable with flex states

  10. 10 Posted by Christen on 23 Jun, 2011 02:22 PM

    Christen's Avatar

    Say you have:
    view 1: this post we are looking at now
    View 2: the overview over all post in this forum

    I want to change from view1 to view2. But before I show view2 to the user I want it compleatly rendered. (so not like this webpage, that renders when it changes.)

    But I dont want to render all the pages on this site when a user enters the site and save it to memory.

    Use case:
    user push button in view1
    view2 starts rendering
    view2 complete rendering
    view 2 switches with view 1

    (and by rendering Im simplifying, in flash I need to setup all the graphic items from the data, start animation, eventlisteners, sounds, and whatever the view needs to do to look nice. This can be a lot of code to start running if the user chooses not to look at view2.)

  11. Support Staff 11 Posted by creynders on 23 Jun, 2011 02:39 PM

    creynders's Avatar

    Either you mediate the containing view (the one that instantiates view1 and view2) and dispatch a signal to "prepare" all data needed by view2, or - I'd definitely choose this option - when the user pushes the button in view1 you instantiate and hide view2 and add it to the stage. Then when view2 completely has been rendered show it.
    Is there a particular reason why you wouldn't want to do that?

  12. 12 Posted by Christen on 24 Jun, 2011 06:57 AM

    Christen's Avatar

    Yes I dont want it to be instansiated before I show it, so the code dont start.

    I properbly should say that view 1 has mediator 1 and view 2 has mediator 2.

  13. Ondina D.F. closed this discussion on 02 Nov, 2011 05:22 PM.

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