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

Web and WebWorks Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Error blackberry is not defined

[ Edited ]

Hi there,


Just so we have a common starting point, this is the minimum I required to get the sample working error free in Ripple.



*** config.xml ***


<?xml version="1.0" encoding="UTF-8"?>

<widget xmlns="http://www.w3.org/ns/widgets"

    <name>Music Files</name>
    <content src="index.html"/>

    <feature id="blackberry.io.dir" />

Without the <feature> element, Ripple provides an error saying that appDirs is not defined, and rightly so. If this sample were be run on a physical device, I would also require the following <rimSmiley Tongueermissions>.



This would need to be added inbetween the <widget></widget> tags.



*** index.html ***


<!DOCTYPE html>
		<div id="log"></div>
		<script type="text/javascript">
			/*global blackberry */

			function log(text) {
				var div = document.createElement('div');
				div.innerHTML = text;

			window.addEventListener('DOMContentLoaded', function () {
				var dirs, subfolder, musicDir;

				if (typeof blackberry !== 'undefined') {
					dirs = blackberry.io.dir.appDirs;
						'dirs.app.storage.path: '
						+ dirs.app.storage.path

					log('<br />');
					for (subfolder in dirs.shared) {
							+ subfolder + '.path: '
							+ eval('dirs.shared.'
							+ subfolder + '.path')
					log('<br />');

					musicDir = dirs.shared.music.path;
					log('Music folder path: ' + musicDir);
			}, false);

For starters, a <div> was created to keep a running log of output (instead of using alerts; to accomodate this, the log function was also created that appends additional <div> elements to the log.


I then added a listener for DOMContentLoaded to ensure that our DOM is fully ready before trying to execute any JavaScript on it.


Within Ripple, there are two loads that tend to happen. The first is when the application gets loaded into the browser, and the second when Ripple takes over and actually loads the content in the Ripple container. There may be a better way to explain that, but that's sort of the gist of it.


That being said, I've included a check for:

if (typeof blackberry !== 'undefined')


The purpose for this is to avoid an error on the 1st load, before Ripple has been loaded, and blackberry isn't defined. On a real device this wouldn't be needed, it's just a quirk of working with Ripple. Even without the if statement, everything will continue to load just fine, but I prefer to avoid error logs where possible.


The remainder of the code is based on the sample here:



Specifically, alerts have been replaced with logs, and some reformatting has also occurred. But beyond that, the functionality is the same.


The end result for me in Ripple is the following output:



With Web Inspector reporting the following:




Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Posts: 276
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Error blackberry is not defined

Thanks a lot for your help. You gave me a good starting point to solve my issue.

I'm not sure why but when Sencha Touch launch my app, blackberry is not defined. Certainly because the weborks.js file has not been loaded yet...


How I solved this :


function initDirs() {

  try {
    dirs = blackberry.io.dir.appDirs;
    musicDir = dirs.shared.music.path;
  catch(e) {
    Ext.defer(function() {
   }, 1000, this);



With this workaround, I'm waiting until blackberry is not undefined... 

Twitter : @LaurentKP
My apps
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Error blackberry is not defined

Glad you managed to find a workaround. I did some more searching and found this in the Sencha forums:



Are you by chance already waiting for the onReady function before executing your main JavaScript core? (i.e. initializaiton, WebWorks calls, etc.) I would expect that waiting on that function to trigger should mean everything has been loaded.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Posts: 1,230
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Error blackberry is not defined

I had a similar issue recently


Note JQuery...


Try this


var bb = false;


$(document).ready(function() {
    if(typeof blackberry == 'undefined') {
        bb = false;
        } else {
        bb = true;
    if(bb) {
        alert('Blackberry found');
        } else {
        alert('Blackberry not found');

I ain't tried this on my DevAlpha yet but it should be fine

Click the like button if you find my posts useful!