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
sujachristy
Posts: 63
Registered: ‎12-10-2012
My Carrier: Vodafone-in
Accepted Solution

How to set an image in bb10..?

i am getting URl not found when i wrote

      image1.setImage("image\Penguins.jpg");

 

my image iS in a folder named "image" the name of image is "Penguins.jpg" 

_______________________________________________________
Help is available everywhere but you have to look at the correct place.
By Me :-)
Please use plain text.
Developer
jtegen
Posts: 6,536
Registered: ‎10-27-2010
My Carrier: Verizon

Re: How to set an image in bb10..?

You have to load external resources with URLLoader and then set the image when the load is "complete". You also have to make certain you package the file with the BAR file.

Make certain the loader is expecting binary data.

Lastly, Unix paths are forward slashes (/). Windows is the only one that does a back splash. AIR might convert that for you, it is just more of a convention.
Please use plain text.
Contributor
bobbydriscol
Posts: 23
Registered: ‎05-04-2012
My Carrier: Telus

Re: How to set an image in bb10..?

 

For general pathing issues which I truely believe this may be, you need to determine where the path 'image/' really is. In the case of AIR development (and any application development vs web development) application development must use URI rather than URL type references. Relative paths such as the one you note below are not easily resolved. 

 

This path is relative to the application, so 'image/Penguin.jpg' would be relative to the application folder. If you are referring to the users image folder, then you may have more success using File.userDirectory to locate the image and load it from there using 

 

var fl:flash.filesystem.File = flash.filesystem.File.userDirectory.resolvePath('image/Penguin.jpg');
var fs:FileStream = new FileStream();
fs.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityerror)
fs.open(fl, FileMode.READ);

 

and then taking the resulting binary data and importing it into a static Loader object in memory.

 

var ba:ByteArray = new ByteArray();
fs.readBytes(ba);

 

var loader:Loader = new Loader();

loader.loadBytes(ba);

 

If you question is more related to general Image request management:

 

To reference supported file formats you can use a few options:

 

 

For the first one, that's the traditional display list element that is attached directly to a movie clip. There's no assumed functionality from the OS.

 

The second one is the BB OS version which includes a lot more native functionality in the class, related to BB specific methods such as minWidth etc that allows you to create an interactive control as opposed to what is considered a more static element that appears as part of the display list in AIR.

 

The third you may use for managing raw binary data to load into a Loader object.

 

So, to replicate what you have in the most simplified way:

 

var loader:Loader = new Loader();

var urlrequest:URLRequest = new URLRequest("image/Penguins.jpg");

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.imageloaded);

loader.load(urlrequest);

this.addChild(loader);

 

function imageloaded(e:Event):void {

      // when image is loaded you may choose to change it's parameters at this point -- images which are not loaded are considered null until the data is received and this event is fired. For example to capture the image width use e.currentTarget.width at this point.

}

 

Please use plain text.
Developer
sujachristy
Posts: 63
Registered: ‎12-10-2012
My Carrier: Vodafone-in

Re: How to set an image in bb10..?

Thank a lot.The forward slah was the issue..

_______________________________________________________
Help is available everywhere but you have to look at the correct place.
By Me :-)
Please use plain text.