AS3 Error: 1078: Label must be a simple identifier - actionscript-3

I have some code not written by me that I'm trying to compile.
public static function getUserInfoObject(info:Array) : Object {
var lastBattleTime:Number = info[7];
var listLength:Number = info[8];
var list:Array = info.slice(9,9 + listLength);
var achievesLength:Number = info[9 + listLength];
var achievements:Array = info.slice(10 + listLength,10 + listLength + achievesLength);
var statsLength:Number = info[10 + listLength + achievesLength];
var stats:Array = info.slice(11 + listLength + achievesLength,11 + listLength + achievesLength + statsLength);
var commonInfo:Array = info.slice(11 + listLength + achievesLength + statsLength,11 + listLength + achievesLength + statsLength + 8);
return
{
"uid":info[0],
"name":info[1],
"chatRoster":info[2],
"status":info[3],
"displayName":info[5],
"list":list,
"achievements":achievements,
"stats":stats,
"commonInfo":commonInfo,
"creationTime":App.utils.locale.longDate(info[6]),
"lastBattleTime":(lastBattleTime == 0?"":App.utils.locale.longDate(lastBattleTime) + " " + App.utils.locale.longTime(lastBattleTime))
};
}
It gives me this error: 1078: Label must be a simple identifier. in every line in return.
Am I blind or dumb or this code is bad?

You should start your return statement with the curly brace, not with new line:
public static function getUserInfoObject(info:Array) : Object {
return { // <-Here
};
}

Related

How much faster could I make this script?

I have noticed that the script is significantly faster when I comment out the line that calls setValues(). Not that it's a super big issue, but I am interested in the different ways (if any) that I could speed the process up. If anyone has some insight, I would greatly appreciate it! It would also help me see where I could make similar optimizations in other parts of my script.
Here is the code in question:
// import new value(s)
if ((numRaw - numDk) > 0) {
var iDate;
var lastRow = getLastDataRow(earSheet, columnToLetter(earSheet.getRange("EAR_DATES_RNG").getColumn()));
var distName = impSheet.getRange("A1").getValue().toString();
var defaultDept = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("All Lists").getRange("A2").getValue().toString();
impData.forEach(function (entry) {
iDate = new Date(entry[0]);
var newEar = earSheet.getRange("A" + lastRow + ":G" + lastRow).getValues(); // init copy
if (currData.get(iDate.getTime()) == null) {
newEar[0][0] = entry[0];
newEar[0][1] = distName;
newEar[0][6] = entry[1];
newEar[0][3] = "Royalties";
newEar[0][4] = defaultDept;
newEar[0][5] = "NOT SPECIFIED";
earSheet.getRange("A" + lastRow + ":G" + lastRow).setValues(newEar);
Logger.log("ADDED: " + entry[1] + " to row: " + lastRow);
addedNewData++;
lastRow++;
}
else {
Logger.log("EXISTING DATA FOUND: " + currData.get(iDate.getTime()));
}
});
}
Using Matt and Cooper's suggestions, I came up with this revised code which is significantly faster:
if ((numRaw - numDk) > 0) {
var iDate;
var prevLastRow = getLastDataRow(earSheet, columnToLetter(earSheet.getRange("EAR_DATES_RNG").getColumn()));
var currLastRow = getLastDataRow(earSheet, columnToLetter(earSheet.getRange("EAR_DATES_RNG").getColumn()));
var rangeSize = numRaw;
var distName = impSheet.getRange("A1").getValue().toString();
var defaultDept = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("All Lists").getRange("A2").getValue().toString();
var newEar = earSheet.getRange("A" + prevLastRow + ":G" + (prevLastRow + rangeSize - 1)).getValues(); // init copy
impData.forEach(function (entry) {
iDate = new Date(entry[0]);
if (currData.get(iDate.getTime()) == null) {
newEar[currLastRow-2][0] = entry[0];
newEar[currLastRow-2][1] = distName;
newEar[currLastRow-2][6] = entry[1];
newEar[currLastRow-2][3] = "Royalties";
newEar[currLastRow-2][4] = defaultDept;
newEar[currLastRow-2][5] = "NOT SPECIFIED";
Logger.log("ADDED: " + entry[1] + " to row: " + currLastRow);
addedNewData++;
currLastRow++;
}
else {
Logger.log("EXISTING DATA FOUND: " + currData.get(iDate.getTime()));
}
});
earSheet.getRange("A" + prevLastRow + ":G" + (prevLastRow + rangeSize - 1)).setValues(newEar);
}```

NodeJS creating JSON using all JSONs uploaded by user

I am trying to make a JSON file using all the JSON files in a directory. Every time a user uploads a new JSON a new combined JSON should be generated. I want the new JSON to have a custom structure hence cant use any libraries. I have the following code:
router.post('/upload', function(req, res) {
var sampleFile;
var bbbid = req.body.bbbid;
DDLFile = req.files.DDLFile;
j++;
DDLFile.mv('/uploads/' + bbbid + '/device' + j + '.json', function (err) {
if (err) {
res.status(500).send(err);
}
else {
res.redirect("fileuploaded");
}
});
var myfiles = [];
var fs = require('fs');
var arrayOfFiles = fs.readdirSync('/uploads/' + bbbid);
arrayOfFiles.forEach(function (file) {
myfiles.push(file);
console.log(myfiles);
});
console.log('No of Files:', myfiles.length);
var files = myfiles.length;
console.log('Files:', files);
console.log('J', j);
var cddl = "{ BBBID:" + bbbid;
if (files == 0) {
cddl = cddl + '}';
console.log('Entered if loop');
}
else {
var i = 0;
/*var obj;
fs.readFile('/uploads/' + bbbid + '/device' + j + '.json', 'utf8', function (err, data) {
if (err) throw err;
obj = JSON.parse(data);
});*/
for (i = 0; i < files; i++) {
console.log('Entered For loop');
console.log('Count:', count);
console.log('Sensor:', sensor);
try{
var obj = fs.readFileSync('/uploads/' + bbbid + '/device' + count + '.json', 'utf8');}
catch(err){
console.log(err);
}
console.log('everything good');
var obj1 = JSON.parse(obj);
console.log('hi');
//JSON.stringify(obj);
var ddl = require('/uploads/' + bbbid + '/device' + count + '.json');
console.log('o');
cddl = cddl + ", {" + obj1.DDL.Sensor.Description.Verbose_Description + ":" + JSON.stringify(ddl) + "}"
JSON.stringify(cddl);
console.log(cddl);
count++;
sensor++;
console.log('Count:', count);
console.log('Sensor:', sensor);
}
cddl = cddl + '}';
JSON.stringify(cddl);
console.log(cddl);
}
});
I want to generate a new cddl everytime a new file is uploaded. Having a lot of problems. Help please!
I see two problems. First instead of this:
var obj = fs.readFileSync('/uploads/' + bbbid + '/device' + count + '.json', 'utf8');}
catch(err){
console.log(err);
}
console.log('everything good');
var obj1 = JSON.parse(obj);
You can write(fix path, if necessary):
var obj1 = require('./uploads/' + bbbid + '/device' + count + '.json')
Then, when you call:
JSON.stringify(cddl);
You're not saving the result anywhere. So you should save it in the place, you need to:
var a = JSON.stringify(cddl);
And when all set, dont forget to write to file back using fs.writeFileSync or async one fs.writeFile.

How can I display a variable in a dynamic text field?

I have an input textfield on the screen and I have it set to the text that a user enters is saved as a variable and is later called upon o be displayed in a dynamic text box. It's kinda like a high score kind of system, but with multiple variables.
Here is the frame actions where the variables are being set (at least I think they are)
button.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
var data:String = username.text + " " + date.text + " " + company.text;
var file:FileReference = new FileReference();
file.save(data, username.text + " " + date.text + " " + company.text + ".txt");
}
button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame_8);
function fl_ClickToGoToNextFrame_8(event:MouseEvent):void
{
nextFrame();
}
var nameperson = username.text;
var dateperson = date.text;
var companyperson = company.text;
And are the actions where I'm trying to display the variables in another frame:
var nScore:Number = 0;
for(var i:Number = 0; i < aQuestions.length; i++)
{
if(aUserAnswers[i].toUpperCase() == aCorrectAnswers[i].toUpperCase())
{
nScore++;
}
if(i == aQuestions.length - 1)
{
score_txt.text = nScore.toString();
}
}
endresult_name.text = nameperson;
endresult_date.text = dateperson;
I believe the problem is that you set these variables straight when you get to your 1st frame (the text inputs are empty at that point). You need to set them after the user have filled them out and clicked on the button:
var nameperson:String;
var dateperson:String;
var companyperson:String;
function fl_MouseClickHandler(event:MouseEvent):void
{
var data:String = username.text + " " + date.text + " " + company.text;
var file:FileReference = new FileReference();
file.save(data, username.text + " " + date.text + " " + company.text + ".txt");
nameperson = username.text;
dateperson = date.text;
companyperson = company.text;
}

AS3: How to check, all zip files has been extracted?

How to check all zip files has been extracted?
var reader: ZipFileReader = new ZipFileReader();
reader.addEventListener(ZipEvent.ZIP_DATA_UNCOMPRESS, zipDataUncompressHandler);
var zipFile: File = new File(zipFilePath);
reader.open(zipFile);
var list: Array = reader.getEntries();
zipFileCount = list.length;
trace(zipFileCount + " Numbers of items");
for each(var entry: ZipEntry in list) {
var filename: String = entry.getFilename();
if (entry.isDirectory()) {
trace("DIR --->" + filename);
} else {
trace("FILE --->" + filename + "(" + entry.getCompressRate() + ")");
reader.unzipAsync(entry);
}
zipFileWritedCount = zipFileWritedCount + 1;
}
function zipDataUncompressHandler(e: ZipEvent): void {
var entry: ZipEntry = e.entry;
var zfile: File = File.userDirectory.resolvePath('somefolder' + File.separator + entry.getFilename());
var fs: FileStream = new FileStream();
fs.open(zfile, FileMode.WRITE);
fs.writeBytes(e.data);
fs.close();
trace("Refresh Scene");
//include "RefreshScene.as";
}
My files were extracted, but I need to check all files are actually extracted.
Is there any way i can do that.
And I am using airxzip while working with zip file.
Also if I can add an loader.
You can shorten zipFileWritedCount = zipFileWritedCount + 1;
By using just a zipFileWritedCount +=1; or even
zipFileWritedCount++;
Anyways for checking the "all files extracted" amount you could try
the Equality == operator as mentioned in the manual.
Quick example :
for each(var entry: ZipEntry in list)
{
var filename: String = entry.getFilename();
if ( entry.isDirectory() ) { trace("DIR --->" + filename); }
else
{
trace("FILE --->" + filename + "(" + entry.getCompressRate() + ")");
reader.unzipAsync(entry);
}
zipFileWritedCount += 1; //add plus 1
if ( zipFileWritedCount == zipFileCount ) //if Equal to zipFileCount..
{
trace ("unzipped all files...");
trace ("zipFileCount: " + zipFileCount + " -VS- " + "zipFileWritedCount: " + zipFileWritedCount )
}
}

How to use mailto attachment in Angular.js

I want to add attachment path, how to add attachment in mailto.
I have tried like following but that not worked.
$scope.sendMail = function ()
{
$scope.to = "To#gmail.com";
$scope.cc = "CC#gmail.com";
$scope.bcc = "bcc#gmail.com";
$scope.subject = "Confirmation";
var link = "mailto:" + $scope.to
+ "?cc=" + $scope.cc
+ "&bcc=" + $scope.bcc
+ "&subject=" + $scope.subject
+ "&body=" + "Test Body";
+"&attachment="
window.location.href = link;
}