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
Developer
ddluk
Posts: 212
Registered: ‎10-02-2010
My Device: Z10 and Z30
My Carrier: Play and Plus
Accepted Solution

Display image

Today I started developing my first application for Playbook and I discovered problem with displaying image on stage. I wrote the following code:

 

 

package 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
		
	import qnx.ui.buttons.Button;
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.display.Image;
	
	[SWF(width="1024", height="600", backgroundColor="#ffffff", frameRate="30")]
	public class unitconv extends Sprite
	{
		public function unitconv()
		{
			var image1:qnx.ui.display.Image;
			image1.setImage("src/forma.png");
			image1.setPosition(0,0);
			image1.setSize(1024,600);
			image1.visible = true;
			stage.nativeWindow.visible = true;
		}
		
	}
}

 

but after running it nothing is displayed. Could you help me with that problem?

 

Please use plain text.
Developer
ddluk
Posts: 212
Registered: ‎10-02-2010
My Device: Z10 and Z30
My Carrier: Play and Plus

Re: Display image

Ok. I found the solution. If someone need to know:

 

 

package 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import qnx.ui.buttons.Button;
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.display.Image;
	import qnx.ui.text.TextInput;

	
	[SWF(width="1024", height="600", backgroundColor="#ffffff", frameRate="30")]
	public class unitconv extends Sprite
	{
		
		public function unitconv()
		{
			
			var image1:Image = new Image;
			image1.setImage('ruler.jpg');
			image1.setPosition(10,10);
			image1.setSize(1024,600);
			image1.visible = true;
			stage.nativeWindow.visible = true;

			addChild(image1);
			
			stage.nativeWindow.visible = true;
		}
		
		private function closeWindow(event:MouseEvent):void{
			stage.nativeWindow.close();
		}


		}
		
	}

 

 

Please use plain text.
Developer
bradcarvey
Posts: 17
Registered: ‎11-22-2010
My Device: PlayBook

Re: Display image

If you create a debug configuration and run your program, an unhandled exception dialog will open with an error message (2035: URL Not Found.).  This is because the src folder is the root.  Change your code to......

image1.setImage("forma.png");

 

I also changed the var line to instantiate the image1 variable.

var image1:qnx.ui.display.Image = new Image();

 

or you could instantiate it on a new line.

var image1:qnx.ui.display.Image;

image1 = new Image;

 

Finally, you need to add the image to the stage.

this.addChild(image1);

Please use plain text.
Developer
bradcarvey
Posts: 17
Registered: ‎11-22-2010
My Device: PlayBook

Re: Display image

Your closeWindow method does not have an event listener, so it will never be called.  You could add a mouse click event listener and close the app, when any mouse click occurs.

 

image1.addEventListener(MouseEvent.CLICK, closeWindow);

 

Brad

 

 

Please use plain text.
Developer
ddluk
Posts: 212
Registered: ‎10-02-2010
My Device: Z10 and Z30
My Carrier: Play and Plus

Re: Display image

Ok. Thank you for your help Brad :smileyhappy: Now I know how to do that.

Please use plain text.
New Developer
ramesh_bh
Posts: 47
Registered: ‎11-25-2010
My Device: Not Specified

Re: Display image

Hi i have tried your code , but i did not find any image on the emulator here is my code please help

 

[SWF(width="1024", height="600", backgroundColor="#708286", frameRate="30")]
	public class ImageTest extends Sprite
	{
		
		public function ImageTest()
		{
			var image1:Image = new Image();
			image1.setImage('sample.jpg');
			image1.setPosition(10,10);
			image1.setSize(200,200);
			image1.visible = true;
			this.addChild(image1);
			stage.nativeWindow.visible = true;
			
		}
}

 

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Display image

hey ramesh,

 

make sure you imported the image class from qnx:

 

 

import qnx.ui.display.Image;

 

place it right after the package declaration. 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
Please use plain text.
New Developer
ramesh_bh
Posts: 47
Registered: ‎11-25-2010
My Device: Not Specified

Re: Display image

Yes Got it !! i was createa a folder under project folder not in the source folder, we have to create our assets folder under source ... Thanks for the reply.

Please use plain text.
Contributor
durvasa
Posts: 14
Registered: ‎12-18-2010
My Device: Not Specified

Re: Display image

in which folder are we supposed to put the image file?

 

I used the same exact code as typed by ramesh_bh above, created a new folder under the src folder,debugged the program, and run it on the emulator.  But no image ever shows up.

 

I've even tried putting the image in other locations, but no image ever shows up, no matter which folder I put the image file in....

 

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Display image

hey durvasa,

 

can you supply us with a sample of the code you are trying out? thanks!

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
Please use plain text.