Javascript error while using EncryptedLocalStore - javascript

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!

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 );
}
...

Related

Cannot read property 'enumNodeFragments' of undefined

I'm trying to change the color of elements in 3D Viewer using the Autodesk-forge platform, and for this I'm using this API https://forge.autodesk.com/cloud_and_mobile/2015/12/change-color-of-elements-with-view-and-data-api.html by Daniel Du.
But the problem is when running I got this
The error Pict
And this the function :
Autodesk.Viewing.Viewer3D.prototype.setColorMaterial = function(objectIds, color) {
var material = addMaterial(color);
for (var i=0; i<objectIds.length; i++) {
var dbid = objectIds[i];
//from dbid to node, to fragid
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
var it = viewer.model.getData().instanceTree;
console.log(it);
it.enumNodeFragments(dbid, function (fragId) {
var renderProxy = viewer.impl.getRenderProxy(viewer.model, fragId);
console.log("r prox : " + renderProxy);
renderProxy.meshProxy = new THREE.Mesh(renderProxy.geometry, renderProxy.material);
renderProxy.meshProxy.matrix.copy(renderProxy.matrixWorld);
renderProxy.meshProxy.matrixWorldNeedsUpdate = true;
renderProxy.meshProxy.matrixAutoUpdate = false;
renderProxy.meshProxy.frustumCulled = false;
viewer.impl.addOverlay(overlayName, renderProxy.meshProxy);
viewer.impl.invalidate(true);
}, false);
});
}
}
Hopefully, anyone has the solution to this problem...
Most likely you are running this code before the instance tree has been loaded, which provokes the error Cannot read property 'enumNodeFragments' of undefined on it variable. You would need to wait for the Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT before running that code.
Take also a look at previous question about modifying materials in the viewer.

firebase - javascript object returning undefined

I have a firebase set up. here is the structure:
I am having trouble getting the 'newNroomID' value (that is a6QVH, a7LTN etc..).
this value will be use to compare with the other variable value.
I know that in javascript, to access the value of the object it can be done like this:
var card = { king : 'spade', jack: 'diamond', queen: 'heart' }
card.jack = 'diamond'
but it seems different story when it comes with the firebase or surely enough i am missing something. Here is my code.
var pokerRoomsJoin = firebase.database().ref(); // this is how i set it up this block of code is for reading the data only
pokerRoomsJoin.on('value', function(data){
var rID = data.val();
var keys = Object.keys(rID);
var callSet = false;
for (var i = 0 ; i < keys.length; i++) {
var indexOfKeys = keys[i];
var roomMatching = rID[indexOfKeys];
var matchID = roomMatching.newNroomID; // this does not work alwaus give me undefined
console.log('this return :' + matchID + ' WHY!')
console.log(roomMatching)
if(matchID == 'ffe12'){ // 'ffe12' is actually a dynamic value from a paramiter
callSet = true;
}
}
})
and here is the result of the console log:
strangely i am able to access it like this
var matchID = roomMatching.newNroomID // it return a6QVH and a7LTN one at a time inside the loop
only if i set up the ref to :
var pokerRoomsJoin = firebase.database().ref('room-' + roomId);
I've tried searching but seems different from the structure i have . am I having bad data structure? Save me from this misery , thanks in advance!
Let us see the code inside for loop line by line,
1. var indexOfKeys = keys[i];
now indexOfKeys will hold the key room-id
2. var roomMatching = rID[indexOfKeys];
here roomMatching will hold the object
{ 'firebasePushId': { newDealerName: 'b',
...,
}
}
Now
3. var matchID = roomMatching.newNroomID;
This of-course will be undefined because roomMatching has only one
property , firebasePushId.
To access newNroomID , you have to do something like this,
matchID = roomMatching.firebasePushKey.newNroomID .
One way to get firebasePushKeys will be using Object.keys(roomMatching).

unable to get property 'value' of undefined or null reference IE11

I have a code that is working fine in ie8 but in ie11 it's giving me error -"unable to get property 'value' of undefined or null reference "while debugging. I am adding just a part of function. If you notice it is working fine for other elements just on isSpanish it is failing. Any suggestions are welcome.
function callSchedule() {
document.getElementById("hideCallbackRow").style.display = "block";
document.getElementById("scheduleCallBtn").disabled = true;
var callbackDate = '';
var callbackCallTimeZone = '';
var callbackCallTime = '';
var spanish = '';
if(document.getElementById("fromDate1") && document.getElementById("requestedCallTimeZoneSelectedVal") && document.getElementById("requestedCallTimeSelectedVal")){
setCallbackValues();
callbackDate = document.getElementById("fromDate1").value;
callbackCallTimeZone = document.getElementById ("requestedCallTimeZoneSelectedVal").value;
callbackCallTime = document.getElementById("requestedCallTimeSelectedVal").value;
spanish = document.getElementById("isSpanish").value;

Cannot Find Function Contains in Object

I'm getting the following error when I call the code listed below it.
Cannot find function contains in object Is Patient Fasting?/# of Hours->Yes; 12 hours.
My code:
var i = 0;
var tempFastingQuest = "";
var tempFastingAns = msg['OBR']['OBR.39'].toString();
while (msg['NTE'][i] != null) {
tempFastingQuest = msg['NTE'][i]['NTE.3']['NTE.3.1'].toString();
if (tempFastingQuest.contains("Yes"))
tempFastingAns = "Y";
i = i + 1
}
What am I missing here?
Assuming this is JavaScript: Strings don't have a contains() method, which the error clearly states. Maybe you are looking for the search() method: if (tempFastingQuest.search('Yes') > -1) ...

javascript to stop specific service

I have the following code in a script.
The problem is That I want to get information of scripts that starts in a specific name and are in a specific startmode.
var e = new Enumerator(GetObject("winmgmts:").InstancesOf("Win32_Service"))
var WSHShell = new ActiveXObject ("WScript.Shell");
var strPrefix = "TTTT";
for(;!e.atEnd(); e.moveNext()){
var Service = e.item();
var strName = Service.Name;
if (strName.substr (0, strPrefix.length) == strPrefix) {
if(Service.StartMode == 'mmManual') {
WScript.Echo("Yes");
}
if(e.StartMode == 'Manual') {
WScript.Echo("Yes");
}
}
}
In the above script I tried to know the start mode but it always return true.
McDowell is right, but note that you can get rid of prefix and start mode checks in your loop if you make them part of the WMI query:
SELECT * FROM Win32_Service WHERE Name LIKE 'TTTT%' AND StartMode = 'Manual'
Using this query, your script could look like this:
var strComputer = ".";
var oWMI = GetObject("winmgmts://" + strComputer + "/root/CIMV2");
var colServices = oWMI.ExecQuery("SELECT * FROM Win32_Service WHERE Name LIKE 'TTTT%' AND StartMode = 'Manual'");
var enumServices = new Enumerator(colServices);
for(; !enumServices.atEnd(); enumServices.moveNext())
{
var oService = enumServices.item();
WScript.Echo(oService.Name);
}
I'm not sure exactly what you're asking, but this...
if(Service.StartMode = 'mmManual')
...will always evaluate to true. You are missing an =. It should be:
if(Service.StartMode == 'mmManual')

Categories

Resources