Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Zeeshan0581
Posts: 86
Registered: ‎01-09-2009
My Device: Not Specified

Re: how to add new screen

Thanks for clearing up the confusion.

 

 

Please use plain text.
Developer
pedgarcia
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

Re: how to add new screen

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!



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators
Please use plain text.
Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: how to add new screen

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.

Please use plain text.
Developer
pedgarcia
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

Re: how to add new screen

Hi,

 

thanks for your suggestions! I think I've got it.

 

I'll try to implement this, and then post the results here.

 

Thanks



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators
Please use plain text.
Developer
pedgarcia
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

Re: how to add new screen

[ Edited ]

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



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to add new screen

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.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to add new screen

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).

Please use plain text.
Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: how to add new screen

[ Edited ]

 


 

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.

 

Please use plain text.
Developer
pedgarcia
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

Re: how to add new screen

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



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators
Please use plain text.
Developer
ddluk
Posts: 212
Registered: ‎10-02-2010
My Device: Z10 and Z30
My Carrier: Play and Plus

Re: how to add new screen

@pedgarcia

 

Could you provide some sample code how you do that?

Please use plain text.