Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Change the depth of a view to keep ontop.  (Read 8756 times)
militia
Newbie
*
Posts: 5


View Profile Email
« 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
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 on: December 07, 2009, 07:11:30 »

You can use addChildAt(displayObj, 0), that would put each new item at underneath the others.
Logged
militia
Newbie
*
Posts: 5


View Profile Email
« Reply #2 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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>
Logged
militia
Newbie
*
Posts: 5


View Profile Email
« Reply #4 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.
Logged
omar
Newbie
*
Posts: 9


View Profile Email
« Reply #5 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 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>
Logged
Pages: [1]
Print