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
Developer
mdd
Posts: 222
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT
Accepted Solution

BB10 Image problem

I've run into an issue trying to update a qnx.fuse.ui.display.Image's bitmapData:

 

here's my code:

function update( bmp:Bitmap ):void
{
var bmd:BitmapData = bmp.bitmapData; if ( bmd is BitmapData ) { trace( _image.width, "x", _image.height, bmp.name, bmd.width, "x", bmd.height ); _image.setImage( bmd ); _image.visible = true;

 

and here's the trace output:

329 x 256 instance1872 341 x 256
ArgumentError: Error #2015: Invalid BitmapData.
	at flash.display::BitmapData/get width()
	at qnx.fuse.ui.display::Image/getRawPreferredSize()[E:\hudson\workspace\BB10_0_09-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\display\Image.as:142]
	at qnx.fuse.ui.display::Image/setImage()[E:\hudson\workspace\BB10_0_09-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\display\Image.as:337]

The new bitmapData seems to be ok, since height and width are non-zero, so it seems to be accessing a previous bitmapData instance (which has been replaced).

I've tried keeping a global reference to the old bitmapData, but same result...

 

Suggestions please...

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: BB10 Image problem

Loading images have a delay before the image and size information is available. You can try listening for Event.COMPLETE on the image loading. In your example is testing the size before the setImage(...) call, try adding a trace after that line for the size of _image to verify that it is being set properly.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: BB10 Image problem

I've may have not addressed the main issue. Where is the bitmap coming from?
Please use plain text.
Developer
Developer
mdd
Posts: 222
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: BB10 Image problem

Yes, I'm aware of the delay, hence the test to see if the bitmapData is set.

 

The images are being loaded from and external server by my ImageLoader and cached in an ImageCache.  The update function gets called when we get Event.COMPLETE.

 

In the problematic case, the original bitmapData in the cache has been reloaded with a new bitmapData instance.

 

Regards

Please use plain text.
Developer
Developer
mdd
Posts: 222
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: BB10 Image problem

to resolve the problem I added the following:

if ( _image.bitmapData )
{
	try
	{
		var testWidth:int = _image.bitmapData.width;
	}
	catch( e:Error )
	{
		var index:int = getChildIndex( _image );
					
		trace( "remove image at:", index, _image.x, _image.y, _image.hAlign, _image.vAlign );
										
		removeChildAt( index );
										
		_image = new Image();
		{
			_image.fixedAspectRatio = true;
		}
		addChildAt( _image, index );
										
		invalidateDisplayList();
	}
}
_image.setImage( bmd );

 ugly, but necessary...

Please use plain text.