I am trying to convert text to ascii codes. Code works outside. But in AI it gives preset WebViewString code
JS Code:
function getCharCodes(s) {
let charCodeArr = [];
for (let i = 0; i < s.length; i++) {
let code = s.charCodeAt(i);
charCodeArr.push(code);
}
return charCodeArr;
}
let webString = window.AppInventor.getWebViewString();
// Ensure charCodes is an array by wrapping it in square brackets
let charCodes = [getCharCodes(webString)];
let charCodesString = charCodes.toString();
window.AppInventor.setWebViewstring(charCodesString);
and don't wrap getCharCodes(webString) in square brackets
function getCharCodes(s) {
let charCodeArr = [];
for (let i = 0; i < s.length; i++) {
let code = s.charCodeAt(i);
charCodeArr.push(code);
}
return charCodeArr;
}
let webString = window.AppInventor.getWebViewString();
let charCodes = getCharCodes(webString);
let charCodesString = JSON.stringify(charCodes);
window.AppInventor.setWebViewString(charCodesString);
I took a shot at adding the WebViewer event to show the changed WebViewString when it was ready, but it was not enough.
There's something in your Javascript, beyond my Javascript skills:
function getCharCodes(s) {
let charCodeArr = [];
for (let i = 0; i < s.length; i++) {
let code = s.charCodeAt(i);
charCodeArr.push(code); }
return charCodeArr; }
let webString = window.AppInventor.getWebViewString();
// Ensure charCodes is an array by wrapping it in square brackets;
let charCodes = [getCharCodes(webString)];
let charCodesString = charCodes.toString();
window.AppInventor.setWebViewstring(charCodesString);
Unfortunately, neither fix changed anything on screen after the button push. data_over_sound1.aia (2.4 KB)
function getCharCodes(s) {
let charCodeArr = [];
for (let i = 0; i < s.length; i++) {
let code = s.charCodeAt(i);
charCodeArr.push(code); }
return charCodeArr; }
let webString = window.AppInventor.getWebViewString();
// Ensure charCodes is an array by wrapping it in square brackets;
let charCodes = [getCharCodes(webString)];
let charCodesString = JSON.stringify(charCodes);
window.AppInventor.setWebViewString(charCodesString);
function getCharCodes(s) {
let charCodeArr = [];
for (let i = 0; i < s.length; i++) {
let code = s.charCodeAt(i);
charCodeArr.push(code); }
return charCodeArr; }
let webString = window.AppInventor.getWebViewString();
let charCodes = [getCharCodes(webString)];
let charCodesString = JSON.stringify(charCodes);
window.AppInventor.setWebViewString(charCodesString);