PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: militia on December 07, 2009, 03:49:46



Title: Change the depth of a view to keep ontop.
Post by: militia on December 07, 2009, 03:49:46
Hi
Using pure as3 - how can i keep all views below the navigation view?

Id like to be able to do ether a addChildAt(0) kind of thing so all new views are added behind the navigation view - it this possible?

Thanks
Monkey


Title: Re: Change the depth of a view to keep ontop.
Post by: Jason MacDonald on December 07, 2009, 07:11:30
You can use addChildAt(displayObj, 0), that would put each new item at underneath the others.


Title: Re: Change the depth of a view to keep ontop.
Post by: militia on December 07, 2009, 01:33:46
No sorry - i know that, but what i dont understand is how to change the depth of a whole view. addChildAt is just within a view i need each view to be behind the main navigation view regardless  of when it is created.


Title: Re: Change the depth of a view to keep ontop.
Post by: puremvc on December 07, 2009, 02:06:46
:
public var topView:String;
public function bringToFront ( viewName:String ):Boolean
{
if (topView == viewName) return false;
var view:DisplayObject = getChildByName( viewName );
removeChild(view);
displayView(view);
return true;
}

private function displayView( view:DisplayObject ):void
{
view.x = 0;
view.y = 0;
view.visible=true;
addChild(view);
topView=view.name;
}

Here's some code snatched from a Flex app I had laying around. I wiped out the Flexyness, and I think it should work in pure AS3. You may need to tailor it to fit your needs.

Use the displayView method to add any DisplayObject to the view and it ends up on the top of the stack. Then always use bringToFront to specifically pull the navigation object to the top of the stack, like this:

:
// Adding the navigation view
navView.name = 'navigationView';
displayView(navView as DisplayObject);

.
. Later...
.

// Add a new view
displayView(myNewView as DisplayObject);
bringToFront('navigationView');


It's one way of doing it...

-=Cliff>


Title: Re: Change the depth of a view to keep ontop.
Post by: militia on December 07, 2009, 04:19:57
Hi Cliff,
Is this only a multicore method?
Dose not recognise the method in single core?

Many thanks for your help.


Title: Re: Change the depth of a view to keep ontop.
Post by: omar on December 07, 2009, 04:24:16
Another thing you can do would be to just add the nav again... so for example:

myNewView <-- Your "new" display object.
myNav <-- your nav which should always be on top
myContainer <-- This guy contains all your "views".

So when you add a new view:
myContainer.addChild( myNewView );

Right after that you can do:
myContainer.addChild( myNav );

Calling add child on your nav will move it to be on top of all the other children.


Title: Re: Change the depth of a view to keep ontop.
Post by: puremvc on December 07, 2009, 04:49:31
The code I posted was framework agnostic, just AS3. No PureMVC there. It should be placed in your main container.

-=Cliff>