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
New Developer
Posts: 47
Registered: ‎11-25-2010
My Device: Not Specified

Re: How to navigate to other page ?

You have to make disable the first screen, then only you can view new screen completely.

Trusted Contributor
Posts: 146
Registered: ‎03-22-2010
My Device: Not Specified

Re: How to navigate to other page ?

[ Edited ]

how to disable previous screen?is there something like hide or i have to remove all controls and draw them later again?

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: How to navigate to other page ?

Hey vijay,

 

you can try to add a large background that fills up the second "page" that way everything is blocked off from being seen. I posted this on another thread so ill repost it here because its related. Its a modified version of the Page1.as and Page2.as. It involves a transition of the Page2. Here's the code:

 

Page1.as:

 

 

package
{
	import caurina.transitions.Tweener;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import qnx.ui.buttons.LabelButton;
	
	[SWF(width="1024",height="600",backgroundColor="#CCCCCC",frameRate="30")]
	public class Page1 extends Sprite
	{
		private var nextPage:Page2;
		private var transBtn:LabelButton;
		
		public function Page1()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			nextPage = new Page2();
			
			/*
			 * Button to get the new screen on screen 
			*/
			transBtn = new LabelButton();
			transBtn.label = "Click to change Screens";
			transBtn.setSize(300,52);
			transBtn.setPosition(100,200);
			transBtn.addEventListener(MouseEvent.CLICK, showNewPage);
			
			addChild(transBtn);
			
			/*
			 * Add the new screen, but it wont be visible because it's x
			 * position is more than the page dimension of 1024 (check other page)
			*/
			addChild(nextPage);
		}
		public function showNewPage(e:MouseEvent):void
		{
			/*
			 * Create the transition to bring the new screen in from x:1024 (off screen)
			 * to x:0 in .3 seconds in a straight line (linear)
			*/
			Tweener.addTween(nextPage, {x:0, y:0, time:.3, transition: "linear"});
		}
	}
}

 

 

Page2.as:

 

 

package
{
	import caurina.transitions.Tweener;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import qnx.ui.buttons.LabelButton;
	
	public class Page2 extends Sprite
	{
		private var pageBackground:Shape;
		private var transBtn:LabelButton;
		
		public function Page2()
		{
			super();
			
			/*
			 * Set the position of the screen at 1024 so it doesnt show
			*/
			this.x = 1024;
			
			/*
			 * Create a "background" for the new page
			*/
			pageBackground = new Shape();
			pageBackground.graphics.beginFill(0xFF0000, 1);
			pageBackground.graphics.drawRect(0,0,1024,600);
			pageBackground.graphics.endFill();
			
			/*
			 * Button to get rid of this screen.
			*/
			transBtn = new LabelButton();
			transBtn.label = "Welcome to Page 2, click here to go back.";
			transBtn.setSize(300,52);
			transBtn.setPosition(100,200);
			

			transBtn.addEventListener(MouseEvent.CLICK, showOldPage);

			/*
			 * add the button and the background
			*/
			
			addChild(pageBackground);
			addChild(transBtn);
			
		}
		public function showOldPage(e:MouseEvent):void
		{
			/*
			 * Create a transition for this page to disappear starting from
			 * x: 0 to x:1024 (off screen) in .3 seconds in a straight line (linear)
			*/
			Tweener.addTween(this, {x:1024, y:0, time:.3, transition: "linear"});
		}
	}
}

 

the comments should explain most of it. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to navigate to other page ?

Depending on how your moving from one page to another, you may have to remove your first page with removeChild before adding your next page.

Developer
Posts: 124
Registered: ‎01-22-2011
My Device: Blackberry Q10
My Carrier: Sprint

Re: How to navigate to other page ?

This is nice.  But if I change the orientation to portrait, the backbround graphic is still sized as 1024x600.  I tried to redraw the background graphic with stage.width and stage.height in the dimensions, but I get an error saying that the stage object is null.  How would I gain access to the stage object in Page2 so that it can be resized.  Or is there another approach that should be taken?

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: How to navigate to other page ?

hey WingFlap,

 

in order to have access to the stage, the object must be a child of a parent that is already on the stage. so you can adjust the background of your page 2 only when it is added via the addChild() method. good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: How to navigate to other page ?

The stage property of a given DisplayObject is null until and unless that object is added to the display list (as in, added to the "main class" instance or some descendent of it).  See this thread for more.

 

The simplest thing to do for individual cases is to listen for Event.ADDED_TO_STAGE, and only reference the stage properties when that occurs.  There are other approaches mentioned in the thread but that may be the cleanest, if it works for you structurally.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to navigate to other page ?

In PageViewStack class in playbook-as3-lib library, the size of the page is set to the stage before it is added.  So an orientation change should can be pciked up by the current page and any page changes after that will have the correct stage dimensions.

Developer
Posts: 124
Registered: ‎01-22-2011
My Device: Blackberry Q10
My Carrier: Sprint

Re: How to navigate to other page ?

Ahhh!

 

I now understand what's up with adding an event listener whose function's first task is to remove the listener and add a listener for the stage event.  Thanks!

Highlighted
Visitor
Posts: 1
Registered: ‎04-01-2011
My Device: Not Specified

Re: How to navigate to other page ?

Hi

 

I have same problem but this once with Item of MenuItem and not with buttom.

 

I created one screen (identication) that extends mainscreen and I want when I click on Item (show) of my menu I want to retrieve aonther screen (detail). I treid the fonction addChild() but the (IDE) don't recognize it  and I don't use the sprite class I use mainscreen. following you will fin my code. please help.

 

identification

 

public class identification extends MainScreen {
	
	

	

	public identification ()

	{
		super();
		LabelField title = new LabelField("Identification",
				LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
		setTitle(title);
		add(new RichTextField("identification file"));

		add(new SeparatorField());

		VerticalFieldManager _fieldManagerTop;

		_fieldManagerTop = new VerticalFieldManager();

		add(_fieldManagerTop);

		BitmapField _bitmap;
		Bitmap _me;
		_logo = Bitmap.getBitmapResource("me.png");

		_bitmap = new BitmapField();
		_bitmap.setBitmap(_me);
		_fieldManagerTop.add(_bitmap);

			}
	

	MenuItem Item = new MenuItem("Show", 0, 0) {
		public void run() {

	identificationstack selecsT = new identificationstack();

		}
	};

	protected void makeMenu(Menu menu, int instance) {
		menu.add(Item);

		super.makeMenu(menu, instance);
	}
	
	

	public boolean onClose() {
		Dialog.alert("Goodbye!");
		System.exit(0);
		return true;
	}
	
	

}



public class identificationstack extends UiApplication{
	
	
	public static void main(String[] args)
	{
		identificationstack theApp = new identificationstack();
	theApp.enterEventDispatcher();
	}
	public identificationstack()
	{
	//display a new screen
	pushGlobalScreen(new identification (), 1000, UiEngine.GLOBAL_SHOW_LOWER);
	}

}

 

for detail screen is

 

public class Detail extends MainScreen {

	public Detail ()

	{
		super();		
		
		LabelField title = new LabelField("I'm here",
				LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
		setTitle(title);
		add(new RichTextField("My name is"));

		add(new SeparatorField());

		VerticalFieldManager _fieldManagerTop;

		_fieldManagerTop = new VerticalFieldManager();

		add(_fieldManagerTop);

		BitmapField _bitmap;
		Bitmap _me;
		_logo = Bitmap.getBitmapResource("me.png");

		_bitmap = new BitmapField();
		_bitmap.setBitmap(_me);
		_fieldManagerTop.add(_bitmap);

	}

	public boolean onClose() {
		Dialog.alert("Goodbye!");
		System.exit(0);
		return true;
	}
}



public class Detailstack extends UiApplication{

	public Detailstack ()
	{
		Detailstack detstack = new Detailstack();
		detstack.enterEventDispatcher();

	//display a new screen
	    pushScreen(new Detail());
	}

}

 

 

Reply please