11-02-2010 06:21 PM
Thanks for clearing up the confusion.
11-03-2010 01:04 PM
So, I'm assuming the right approach to open new Views is basically create a new instance of some window using something like:
var aView:AnotherSprite = new AnotherSprite()
But one thing is not clear to me so far. How do I change the current active Window? I've tried playing with stage.addChild and addChildAt. Although the new window is displayed, the old one is still visible as well.
It will be nice if someone could post a basic mechanism to open new windows and, when it's close, the old one gets the place.
Any ideas?
Thanks in advance!
11-03-2010 03:58 PM
You can either removeChild(oldVIew), or simply oldView.visible = false (or oldView.alpha = 0 but you don't want to do that)
Simple way to manage this is to write your own viewStack class, and you can say viewStack.push(newView), or viewStack.pop();
ViewStack can just take care of toggling visiblity of the old view. If you want to go a bit further, viewStack can manage transitions in and out.
Also, in terms of performance, removing from stage will yield the best results, but setting visible to false will mean that the displayObject is not rendered at all, which takes care of most of the cost for that object, so either method is pretty solid.
Setting alpha to 0 is the worst solution, as your item is still being rendered even though it's not visible.
11-03-2010 09:02 PM
Hi,
thanks for your suggestions! I think I've got it.
I'll try to implement this, and then post the results here.
Thanks
11-05-2010 03:43 PM - edited 11-05-2010 03:44 PM
Hi,
When the application starts I'm already instantiating a Sprite-derived class (MainSpriteClass). In the AIRHelloWorld source code, we set "stage.nativeWindow.visible = true" at the end of this class constructor. As I could understand, setting it is that actually shows the MainSpriteClass object.
Let's say I have to other Sprite-derived classes: AnotherView1 and AnotherView2, and I want to show AnotherView1 automatically when the application starts, and if the user clicks a button or whatever, this AnotherView1 will be closed, and AnotherView2 will be shown.
I understand that if, from MainSpriteClass, I could call removeChild(anotherView1) and then, addChild(anotherView2), it should work, shouldn't it?
But, since the MainSpriteClass is behind them (and possibly inactive), how AnotherView1 could close itself, or at least notify the MainSpriteClass to close it and open the other.
I've found some examples about screen stacks, but it seems they always have some kind of interface from the main windows (like tabs, etc...). How can I do that when I have all my sub-screens using the whole screen? Thanks again
11-05-2010 04:04 PM
It is best to use the ViewStack class to manage multiple views in a "stack". The ViewStack would be added to your "base" Sprite as full screen, and then your views would be added as children to the view stack. Only 1 view can be seen at one time and the view stack allows you to select which view to show. Once the effects are possible in the BB SDK, when a view changes, you can define a transition (fade, slide, etc).
Dont know if its an issue with BB SDK, but in MXML, you have to make certain that the "creation policy" is set to "all" or the child views dont get fully added to the display list until activated for the first time.
Hope that helps.
11-05-2010 04:07 PM
One other thing.
Your added child views would listen to a gesture to transition from one view to another. Send the message to the parent view to determine direction (right=next, left=previous) and you could have it set to go round-robin when it reaches one of the end views (first or last).
11-07-2010 06:33 AM - edited 11-07-2010 10:39 AM
But, since the MainSpriteClass is behind them (and possibly inactive), how AnotherView1 could close itself, or at least notify the MainSpriteClass to close it and open the other.
This can be done easily with basic events.
In parent view:
view1.addEventListener("Close", closeWindow1);
view2.addEventListener("Close", closeWindow2);
In child view:
dispatchEvent("Close");
You will want to come up with your own event schema and not string literals, but that is the basic functionality.
Another method would be a singleton "Model" with a currentView property. When currentView is changed, Model dispatches an event, the mainView can then respond to that event and display the appropriate view.
11-07-2010 09:57 PM
This is just a feedback. Thanks for all suggestions. Now I have a simple ViewerStack up and running.
I've implemented using a singleton class that is created at the beginning, and implement a push() and a pop() method. I'm not using any fancy transitions, but probably I'm gonna use at some point.
Now I have the basics to really start the application I'm planning to do.
Thanks
Paulo
11-27-2010 08:57 AM
@pedgarcia
Could you provide some sample code how you do that?