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

Posts: 41
Registered: ‎07-07-2009
My Device: Not Specified
Accepted Solution

qnx.ui.display.Image sizing issue

[ Edited ]

I found something weird about qnx.ui.display.Image setSize. I have an Image object does not display the enlarging size that I set during constructor, but instead display in actual image resolution. But it did display well with enlarging size during mouse event function. I really have no idea what's going on... Thanks in advance for help Smiley Happy



	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import qnx.ui.display.Image;

	[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
	public class AIRHelloWorld extends Sprite
		private var image1:Image;
		public function AIRHelloWorld()
			image1 = new Image;
			image1.setImage('assets/abc.png'); // image resolution 57 x 57
			image1.setPosition(200, 10);
			image1.setSize(77, 77); // it does NOT display 77 x 77 size, but 57 x 57 instead
			image1.addEventListener(MouseEvent.MOUSE_DOWN, downWindow);
			image1.addEventListener(MouseEvent.MOUSE_UP, upWindow);
stage.nativeWindow.visible = true;
} private function downWindow(event:MouseEvent):void{ image1.setPosition(200 - 10,10 - 10); image1.setSize(77,77); // it did display 77 x 77 well here... } private function upWindow(event:MouseEvent):void{ image1.setPosition(200,10); image1.setSize(57,57); } } }



Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: qnx.ui.display.Image sizing issue

Try setting the size after being added to the display list (after addChild()).

Posts: 41
Registered: ‎07-07-2009
My Device: Not Specified

Re: qnx.ui.display.Image sizing issue

Thanks for reply, John! I have tried to set the size after addChild() and stage.nativeWindow.visible = true, but no clue. Any other suggestion? Thanks!

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

Re: qnx.ui.display.Image sizing issue



so i found that when you first declare the image and add it to the parent object its just instructions telling it what to do. however, you are giving instructions to an empty object. It's like that rule where a sprite has no dimension of width or height unless you add children to it. so this applies to this case as well. until the image is loaded setting it's width and height does nothing because it has no "children" in the object. once the image is loaded by the application it finally has dimension and can be modified. so what i recommend is attaching an event listener to listen for when the image is loaded like below:



var myImage:Image;


myImage = new Image();
myImage.addEventListener(Event.COMPLETE, onLoad);
myImage.setPosition(600,300); //dont mind this just random


public function onLoad(e:Event):void
	var myImageObject:Image = (e.target as Image);



to us its loaded instantly but to the runtime its not yet loaded so nothing can be done to it before its loaded. so once its loaded you should be able to manipulate it how you like. hope that helps! 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
Posts: 41
Registered: ‎07-07-2009
My Device: Not Specified

Re: qnx.ui.display.Image sizing issue

Thanks, it works great!

New Contributor
Posts: 3
Registered: ‎12-15-2010
My Device: Not Specified

Re: qnx.ui.display.Image sizing issue

This is a race condition since the result depends on what completes first - the layout thread or the image loading thread. Smiley Sad I suspect you're going to need some form of memory barrier that resizes the image when both the image and sizing data are available.


Useful links

1. http://stackoverflow.com/questions/3047099/why-doesnt-flex-support-threads

2. http://en.wikipedia.org/wiki/Memory_barrier