11-27-2010 08:09 AM
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?
Solved! Go to Solution.
11-27-2010 08:42 AM
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();
}
}
}
11-27-2010 08:58 AM
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);
11-27-2010 09:10 AM
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
11-27-2010 09:11 AM
Ok. Thank you for your help Brad
Now I know how to do that.
12-02-2010 01:08 AM
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;
}
}
12-02-2010 01:13 AM
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!
12-02-2010 01:22 AM
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.
12-18-2010 05:51 PM
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....
12-18-2010 05:56 PM
hey durvasa,
can you supply us with a sample of the code you are trying out? thanks!