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
Accepted Solution

How to navigate to other page ?

Hi ,

 

I want to navigate my page to other when i click the button, here is my code :

 

public class Page1 extends Sprite
 {
  public var page2Smiley Tongueage2;  
  public function Page1()   {
  
   var btn:Button = new Button();
   var lab:Label = new Label();
   
   lab.text = "Click";
   btn.addChild(lab);
   btn.setPosition(10,50);
   btn.addEventListener(MouseEvent.CLICK,dothis);
   addChild(btn);
   addChild(log);
   stage.nativeWindow.visible = true;
   
  }
  public function dothis(event:Event):void {
   page2 = new Page2();
   addChild(log);  

}   
}

But it did not worked out. Please help ?

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

Re: How to navigate to other page ?

[ Edited ]

Hey ramesh,

Put the page2 = new Page2(); in the Page1() constructor and in the dothis() function just put addChild(page2): and it will show the new page2. I don't see where u declared the 'log' object though.

 

Edit: now that im on a computer i can write out the corrected code formatted:

 

 

package
{
	//Remember to import all of the classes that you
	//are using
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	// The following metadata specifies the size and properties of the canvas that
	// this application should occupy on the BlackBerry PlayBook screen.
	[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
	public class MyDocumentClass extends Sprite
	{
		private var page2:Page2;
		
		public function MyDocumentClass()
		{
			//initiate new object here to use later
			page2 = new Page2();
			
			var btn:Button = new Button();
			var lab:Label = new Label();
			
			lab.text = "Click";
			btn.addChild(lab);
			btn.setPosition(10,50);
			btn.addEventListener(MouseEvent.CLICK,dothis);
			addChild(btn);
			
			//addChild(log); //dont know where you declared this so commented out
			stage.nativeWindow.visible = true;
		}
		//change the event to MouseEvent since that is what you
		//are listening for
		public function dothis(event:MouseEvent):void {
			
			addChild(page2);
			//addChild(log); //dont know where you declared this so commented out
			
		}   
	}
}

 

 

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

Re: How to navigate to other page ?

i tried your solution, but nothing even page1 also not displaying,

 

public class Page1 extends Sprite
 {
  
  public var page2Smiley Tongueage2;
  public function Page1()
  {
  
   var btn:Button = new Button();
   var lab:Label = new Label();
   page2 = new Page2();
   lab.text = "Click";
   btn.addChild(lab);
   btn.setPosition(10,50);
   btn.addEventListener(MouseEvent.CLICK,dothis);
   addChild(btn);
   stage.nativeWindow.visible = true;
   
  }
  public function dothis(event:Event):void {
   addChild(page2);
  }
  

   
 }

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

Re: How to navigate to other page ?

you have compile time errors in your code that need to be fixed. here is the corrected code from my other post. now assuming you have all your classes set up this should run:

 

 

package
{
	//Remember to import all of the classes that you
	//are using
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	// The following metadata specifies the size and properties of the canvas that
	// this application should occupy on the BlackBerry PlayBook screen.
	[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
	public class MyDocumentClass extends Sprite
	{
		private var page2:Page2;
		
		public function MyDocumentClass()
		{
			//initiate new object here to use later
			page2 = new Page2();
			
			var btn:Button = new Button();
			var lab:Label = new Label();
			
			lab.text = "Click";
			btn.addChild(lab);
			btn.setPosition(10,50);
			btn.addEventListener(MouseEvent.CLICK,dothis);
			addChild(btn);
			
			//addChild(log); //dont know where you declared this so commented out
			stage.nativeWindow.visible = true;
		}
		//change the event to MouseEvent since that is what you
		//are listening for
		public function dothis(event:MouseEvent):void {
			
			addChild(page2);
			//addChild(log); //dont know where you declared this so commented out
			
		}   
	}
}

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

Re: How to navigate to other page ?

Hi Thanks again for the reply and code.

I have copied and pasted the same code in my application, but blank scree(black) has appeared,

i have commented the page2= new page2(); line and ran again, then my button (Click) appeared on the screen. Dont know what's the problem.

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

Re: How to navigate to other page ?

No problem at all Ramesh! what does your Page2 class look like and where is it placed?

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

Re: How to navigate to other page ?

This is my Page2 class and was placed in the same package (default)

 

public class Page2 extends Sprite
 {
  public function Page2()
  {
   var label:LabelButton = new LabelButton();
   label.label = "Welcome to Second Page";
   addChild(label);
   stage.nativeWindow.visible = true;
  }
 }

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

Re: How to navigate to other page ?

ok there were some compile time errors in your Page2 class. but no worries i got to em. here is the corrected code for Page1 Class:

 

 

package
{
	//Remember to import all of the classes that you
	//are using
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import qnx.ui.buttons.LabelButton;
	
	// The following metadata specifies the size and properties of the canvas that
	// this application should occupy on the BlackBerry PlayBook screen.
	[SWF(width="1024", height="600", backgroundColor="#FFF000", frameRate="30")]
	public class Page1 extends Sprite
	{
		private var page2:Page2;
		
		public function Page1()
		{
			//initiate new object here to use later
			page2 = new Page2();
			
			var labButton:LabelButton = new LabelButton();
			
			labButton.label = "Click";
			labButton.setPosition(10,50);
			labButton.addEventListener(MouseEvent.CLICK,dothis);
			
			addChild(labButton);
			
			//addChild(log); //dont know where you declared this so commented out
			stage.nativeWindow.visible = true;
		}
		//change the event to MouseEvent since that is what you
		//are listening for
		public function dothis(event:MouseEvent):void {
			
			addChild(page2);
			//addChild(log); //dont know where you declared this so commented out
			
		}   
	}
}

 

 

and here is the corrected code for your Page2 class:

 

 

package
{
	import flash.display.Sprite;
	
	import qnx.ui.buttons.LabelButton;
	
	public class Page2 extends Sprite
	{
		public function Page2()
		{
			var label:LabelButton = new LabelButton();
			label.label = "Welcome to Second Page";
			addChild(label);
		}
	}
}

 

in your first Page1 class i combined the label and the button into QNX's LabelButton() class. this code should now run properly (tested and it went fine).

 

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

Re: How to navigate to other page ?

Thanks it worked for me also!! Thanks again....  Man Happy

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

Re: How to navigate to other page ?

hello all,

 

i am facing problem while navigating from one page to another,

 

when i navigate to other page using addchild(), contents of new page come on fisrt page i.e i dont get full new window.

 

pls reply.