views:

17

answers:

1

Hi people,

I am trying to make my first JS-based adobe air app.

But I've stuck at a point.

Here's the code which is causing the error

  var RunUrl  =   'http://www.lilpirate.net';
  var firstRunUrl =   'http://www.netbloo.com';
  var snxApp   = air.EncryptedLocalStore.getItem( 'snxApp' );
  var semail   =   snxApp.readUTFBytes( snxApp.bytesAvailable );
  if( semail!='786') {
     data = new air.ByteArray();
     data.writeUTFBytes( '786' );
     air.EncryptedLocalStore.setItem( 'snxApp', data ); 
     var snxUrlToLoad    =   firstRunUrl;
  }
  else
     var snxUrlToLoad    =   RunUrl;  

When compiling it from adl, it throws error -

TypeError: Result of expression 'snxApp' [null] is not an object.

Help!

A: 

You are accessing properties (bytesAvailable and readUTFBytes) of snxApp without checking to make sure it exists first. If you haven't used setItem to store anything with that name yet, it will be null.

Here's an example of how it would look with an if statement:

var snxApp = ...;
var semail;
if (snxApp !== null) {
    semail = snxApp.readUTFBytes( snxApp.bytesAvailable );
}
...
Matthew Crumley
Yep. I worked it around by using try and catch functions. It works great now :-) Thanks!
KPL
@KPL: try/catch works, but the code might be more clear if you add an `if (snxApp !== null)` check before you set `semail`.
Matthew Crumley