topleft topright

Welcome, Guest. Please login or register.
June 18, 2013, 07:26:42 PM
Home Help Search Login Register
News: ATTENTION: Spambots must die! Humans must visit http://contact.futurescale.com to request forum access.

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


View Profile
« on: December 07, 2009, 03:49:46 AM »

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
« Reply #1 on: December 07, 2009, 07:11:30 AM »

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


View Profile
« Reply #2 on: December 07, 2009, 01:33:46 PM »

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: 2791



View Profile WWW
« Reply #3 on: December 07, 2009, 02:06:46 PM »

Code:
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:

Code:
// 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
« Reply #4 on: December 07, 2009, 04:19:57 PM »

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
« Reply #5 on: December 07, 2009, 04:24:16 PM »

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: 2791



View Profile WWW
« Reply #6 on: December 07, 2009, 04:49:31 PM »

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
Jump to:  



Login with username, password and session length

Powered by SMF 1.1.11 | SMF © 2006-2007, Simple Machines LLC
Copyright © 2006-2008 Futurescale, Inc.