firefox won't convert string to number in flex - apache-flex

I making a web app in Flex using global coordinates
I get the coordinates as strings from a web service then I do something like this:
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This works PERFECT on IE and chrome, from the web server and when debugging locally, but Firefox just works when debugging locally and not from the web server, in the web server cLat and cLong return "NaN".
check it out yourself, it should pop up an alert when you click on a result:
http://mundobuk.com/prueba/mapa/main.html?buscar=oxxo
so I tried using parseFloat(), but it rounds cLat to 28 and cLong to -106 :(
Then I tried separating the decimals form integers, like from my example 28 and 7242100786401 then divide 7242100786401/10000000000000 = 0.7242100786401
having 2 numbers 28 and 0.7242100786401 I add them up
28 + 0.7242100786401 = 28.7242100786401
here is in code form:
var latArr:Array = latStr.split(".");
var longArr:Array = longStr.split(".");
var latDivStr:String = "1";
for (var i:int= 0; i< latArr[1].length; i++){
latDivStr += "0";
}
var longDivStr:String = "1";
for (var j:int = 0; j< longArr[1].length; j++){
longDivStr += "0";
}
var cLat:Number = parseFloat(latArr[0]) + arseFloat(latArr[1])/parseFloat(latDivStr);
var cLong:Number = parseFloat(longArr[0]) - parseFloat(longArr[1])/parseFloat(longDivStr);
again, this way works great everywhere, just not in firefox in the web server >_>
anyone have any ideas? im going crazy whit this #_#

Comma is the separator for many European countries, so it's most likely the regional configuration on either the server or the client.

I have never hear of such an error as The Flash run-time is supposed to make the different browsers and OS's interpret the SWF the same way. I will say that I don't believe you should be using "new" in-front of your Number casting.
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This should be:
var cLat:Number = Number(latStr); //Number is right because its a Floating Point, but remove new.
var cLong:Number = Number(longStr); //Number is right because its a Floating Point, but remove new.
I tested the using the following and saw no rounding take place.
var latStr:String = "28.7242100786401";
var longStr:String = "-106.12635420984";
trace(parseFloat(latStr)); //Outputs: "28.7242100786401";
trace(parseFloat(longStr)); //Outputs: "-106.12635420984";
trace(Number(latStr)); //Outputs: "28.7242100786401";
trace(Number(longStr)); //Outputs: "-106.12635420984";
I do not see why you require this workaround. Also I use firefox as my main browser and your site seems to be working just fine.
Cheers.

I finally found out why its not working, for some reason in firefox instead of reading a dot (.) it reads a comma (,) from the web service (done in vb.net)
locally it reads it as a dot too, not online, so I suppose it has to do something with my IIS server O_o
hope this helps someone out there...

Related

More efficient way to add multiple records

So this works but it takes 15 seconds for a spreadsheet with 60 items.
function addToModel(name,birth,age){
var newRecord = app.models.ImportData.newRecord();
newRecord['PRESIDENT'] = name;
newRecord['BIRTH_PLACE'] = birth;
newRecord['AGE_ELECTED'] = age;
app.saveRecords([newRecord]);
}
function getSpreadsheet(){
var sh = SpreadsheetApp.openById("zzz");
var ss = sh.getSheetByName("Sheet1");
var data = ss.getDataRange().getValues();
THIS WAS WAY ONE, TAKES 15 SECONDS
for (var i=1; i<data.length;i++)
{
addToModel(data[i][1],data[i][2],data[i][3].toString());
}//for loop
}
but I noticed that the command is saveRecordS not saveRecord and with anything in google apps script, the fewer calls the better, so I tried this but it doesn't work
//SAME SPREADSHEET INFO
var result = [];
for (var i=0; i<data.length;i++)
{
var newRecord = app.models.ImportData.newRecord();
newRecord['PRESIDENT'] = data[i][1];
newRecord['BIRTH_PLACE'] = data[i][2];
newRecord['AGE_ELECTED'] = data[i][3].toString();
result.push(newRecord);
}//for loop
app.saveRecords([result]);
Expected result: new records in my table, much faster than the first version. Actual result: "Cannot read property "key" from undefined" which is triggered from the last line (saveRecords). I tried both app.saveRecords(result) and ([result]), same problem both times.
Note: this example is from an appmaker university tutorial that no longer works because of the changes for appmaker v2.
I think that it's model.newRecord() takes time for each new item created, while time on app.saveRecords() is ignorable.
Could you please confirm that you are EU user? as we EU user are facing same issue (link) due to the server location, if it is the case, please help star that issue and give more info to help Google solve that issue. Thanks.

xpages view panel display computed icon

I'm trying to display an icon in a view panel based on a column value. This page will display if I only display the column value and/or use a static database image. If however I try to compute the image based on the column value I get an Http Code 500 error. Looking at the error-log I see two errors, the first is CLFAD0211E: Exception thrown and the second CLFAD0246E: Exception occurred servicing request for .
I have reviewed this simple explanation on how to add a dynamic icon (https://www.youtube.com/watch?v=27MvLDx9X34) and other similar articles and still not working. Below is the code for the computed icon.
var urlFull:XSPUrl = new XSPURL(database.getHttpURL());
var url = urlFull.getHost();
var path = "/icons/vwicn";
// var idx = rowData.getColumnValues().get(1); Removed for testing
var idx = "82.0"; //Hard coded the value for testing
if (idx < 10){
path += ("00" + idx).left(3);
}else if (idx < 100){
path += ("0" + idx).left(3);
}else {
path += idx.left(3);
}
path += ".gif";
//path = "/icons/vwicn082.gif"; I have also tried hard coding the path value - still a no go
url = setPath(path);
url.removeAllParameters();
return url.toString();
The view panel is configured as xp:viewPanel rows="40" id="viewPanel1" var="rowData".
Any suggestions on what to look for or a better option to compute a view panel icon would be appreciated.
Cheers!!!
You have a typo: url = setPath(path);should be url.setPath(path);

Google Sheets: delete rows containing specified data

I'm new to Java scripting and Google Apps Scripts so i am sorry if this has already been answered. I was not able to find what i was looking for over the last few months of working on this project.
I am working on a variant of the scripts here:
Delete row in Google Sheets if certain "word" is found in cell
AND
Google Sheet Script - Find Value in Col and Delete Row
I want to create a button, or menu, that will allow someone to enter specific data, and have each row in the spreadsheet containing that data deleted.
I have a test sheet here that illustrates the data i'm working with, formulas i'm using, and has the beginning of the script attached to it:
https://docs.google.com/spreadsheets/d/1e2ILQYf8MJD3mrmUeFQyET6lOLYEb-4coDTd52QBWtU/edit?usp=sharing
The first 4 sheets are pulling data from the "Form Responses 1" sheet via a formula in cell A:3 in each sheet so the data would only need to be deleted from the "Form Responses 1" sheet to clear it from the rest of the sheets.
I tried working this in but i do not think i am on the right track.
https://developers.google.com/apps-script/guides/dialogs
I also posted this on Google Docs Help Forum 60 days ago, but have not received any responses.
Any help would be greatly appreciated.
There's a few steps. For usability of UI this takes a little longer code. In concise form:
The user activates a dialog and enters a string.
Rows w/ the string are deleted (with error handling and confirmation)
(Hopefully this gets you started and you can tailor it to your needs)
Function that initiates the menu:
function onOpen(){
SpreadsheetApp.getUi()
.createMenu('My Menu')
.addItem('Delete Data', 'deleteFunction')
.addToUi();
}
The main workhorse:
function deleteFunction(){
//declarations
var sheetName = "Form Responses 1";
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName(sheetName);
var dataRange = sheet.getDataRange();
var numRows = dataRange.getNumRows();
var values = dataRange.getValues();
var delete_string = getUIstring();//open initial UI, save value
if (delete_string.length < 3) return shortStringError()//UI to protect your document from an accidental entry of a very short string.
//removing the rows (start with i=2, so don't delete header row.)
var rowsDeleted = 0;
for (var i = 2; i <= numRows; i++){
var rowValues = values[i-1].toString();//your sheet has various data types, script can be improved here to allow deleting dates, ect.
if (rowValues.indexOf(delete_string) > -1){
sheet.deleteRow(i - rowsDeleted);//keeps loop and sheet in sync
rowsDeleted++;
}
}
postUIconfirm(rowsDeleted);//Open confirmation UI
}
Isolated UI functions to help make above function more concise:
function getUIstring(){
var ui = SpreadsheetApp.getUi();
var response = ui.prompt("Enter the target data element for deletion")
return response.getResponseText()
}
function postUIconfirm(rowsDeleted){
var ui = SpreadsheetApp.getUi();
ui.alert("Operation complete. There were "+rowsDeleted+" rows deleted.")
}
function shortStringError(){
var ui = SpreadsheetApp.getUi();
ui.alert("The string is too short. Enter a longer string to prevent unexpected deletion")
}
I'll just show a way to delete the cell value if it matches your search criteria. It's up to you to connect it to buttons ,etc.
You'll loop through a Sheet Range. When you find the word match, delete it using clearContent()
function deleteSpecificData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("Sheet1!A1:C4");
var values = range.getValues();
var numArray = [1,2,3,4,5,6,7,8,9];
var deleteItem = "Garen";
Logger.log(range);
for(var i=0; i< values.length; i++){
for(var j=0; j<values[i].length; j++){
if(values[i][j] == deleteItem){
var row = numArray[i];
var col = numArray[j];
var range = sheet.getRange(row,col).clearContent();
}
}
}
}
Before:
After:

How to use superscripting in flex?

I want to add a label in flex to display m/s2 (read meters per second square). I would need to use superscripting for this.
I have tried out the following code which is giving me a compilation error.
var richtxt1:RichText = new RichText();
richtxt1.text="m/s";
var richtxt2:RichText = new RichText();
var span:SpanElement = new SpanElement();
span.text = "2";
span.baselineShift = "superscript";
richtxt2.addChild(span);
richtxt1.text=rixhtxt1.txt + richtxt2.text
I am getting a compilation error for the line richtxt2.addChild(span)
The error is
Implicit coercion of a value of type flashX.textLayout.elements.SpanElement
to unrelated type flash.Display.DisplayObject
I think you've to do something like this
var xmlText:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" +
"m/s <span baselineShift='superscript'>2</span>" +
"</TextFlow>";
var txtFlow:TextFlow = TextFlowUtil.importFromXML(xmlText);
var richTxt:RichText = new RichText();
richtxt.textFlow = txtFlow;
I've not tested it so please excuse me of any compilation errors.
This is the code I used in my iPad app to accomplish the above:
var xmlText:String = "m/s <span baselineShift='superscript'>2</span>";
var txtFlow:TextFlow = TextFlowUtil.importFromString(xmlText);
var richTxt:RichText = new RichText();
richTxt.textFlow = txtFlow;
this.addElement(richTxt);
It is based on kaychaks and information I found from Adobe's website. The differences are
I took out the TextFlow markup but left in the HTML;
importFromString rather than importFromXML; and
I added this.addElement(richText) to display the element.

string concatenation inside jquery selectors

I am developing a application in C#, ASP.NET and I have a lot os divs in my page, each div is a container for a chat message and each div have a unique id: like this
"<div id='" + myMsgs[j].id_chat_message + "' style='padding: 10px;'>"
so, each div have the same id in page and in database.
now a want to find some div, with jquery, but it doesnt work
for (var j = 0; j < myMsgs.length; j++) {
findDiv = $('#<%= ' + myMsgs[j].id_chat_message + '.ClientID%>');
}
i know that my problem is the concatenation of the strings, but i dont know how to solve it.
When you try to use server tags in the aspx page like that, you are telling ASP .NET to process the page during rendering and replace all those tags with their corresponding values or evaluations. Since you're trying to build the string inside the server tags dynamically using JavaScript, ASP .NET isn't going to process that string and you'll end up with code like this:
$("#<%=id1.ClientID %>")
ASP .NET only processes this type of tag when it renders the page (which is already finished), and this is running on the client-side only, so this isn't going to work.
You should be able to just do this:
for (var j = 0; j < myMsgs.length; j++) {
findDiv = $('#' + myMsgs[j].id_chat_message);
}
the simplest approach would be: add a class-property, which you can then access via jQuery - eg.
var messageBoxes = $('.mySpecialCssClass');
you can now iterate over this array and do something with jQuery/javaScript!
According to your code "myMsgs" should be something like this (in javascript):
var myMsgs = [{"id_chat_message":"id1"},{"id_chat_message":"id2"},{"id_chat_message":"id3"}];
Which would mean this will let you get at the divs you want:
for(var j = 0, l = myMsgs.length; j < l; ++j){
$("#" + myMsgs[j].id_chat_message);
}
But there is probably a better way to do what you want.
Can you provide some more details?

Resources