Very new to actionscript,
Im trying to link two arrays. Basically I have a word array of 8 words and I have a movie clip array of 8 movieclips. My aim is to link the two arrays so that the user must click the right movie clip that matches the word that was displayed on screen.
All help is greatly appreciated!!
var listAry:Array = [];
var orangeJuice:Object = new Object();
orangeJuice.name= "Orange Juice";
orangeJuice.matchingImage=oj;
listAry[0]=orangeJuice;
////etc etc
There you go buddy. Hope that helps if you have any questions just ask.
Another way to do this is with a Dictionary.
var foodionary:Dictionary = new Dictionary();
foodionary["Orange Juice"] = oj;
foodionary["Sandwich"] = sand;
//etc...
for(var key:String in foodionary) {
trace(key + " matches with " + foodionary[key].id); //assuming your images have ids
}
For random access, though, you'll still need an array (or a Vector):
function displayword(){
randomnumber = Math.floor(Math.random() * randomlistword.length);
trace("random number = " + randomnumber);
var chosenword = randomlistword[randomnumber];
randomword.text = chosenword
randomword.img = foodionary[chosenword];
randomlistword.splice(randomnumber, 1);
trace("randomlistword array: " + randomlistword);
}//close displayword function
Related
function myFunction() {
/////////////////////////////////////Fill planning/decor package
var managementSheet = SpreadsheetApp.openById("1P3EF4Edu0efzJVV1Sx-0ayAPaAAiRK8Sl0Y1qZHmcf4");
var packageSheet = managementSheet.getSheetByName("Order Contents");
//Order Contents iterater
var c = packageSheet.getMaxColumns();
var n = packageSheet.getLastRow();
var items = packageSheet.getRange(2,1,n,c).getValues();
var filteredItems = items.filter(function(row) {
if(row[2].toString().includes(firstName +" "+lastName))
{
var results =new Array();
var info = new Array();
info[0]=row[3];
info[1]=row[5];
info[2]=row[9];
info[3]=row[14];
info[4]=row[15];
info[5]=row[16];
results[0]= info;
// result = results.every().valueOf();
Logger.log(results)
var row=22
results.forEach(function(value, index) {
Logger.log("The value at index " + index + " is " + value + ".");
generatedInvoice.getRange(22,1,1,7).setValues([[info[0],,info[1],info[2],info[3],info[4],info[5]]])
row= index + 22+1
})}})
}
Hello. First off, I'm new to appscript/javascript/script in general... Secondly, I'm the worst at explaining things and am so over this as I've been working on it for 2 days with only a few food/water/sleep breaks and just can't figure it out.
I'm trying to take rows from one sheet and copy only some of that row's values to a template...
Customer orders are on one sheet.
Order CONTENTS(for all customers' orders) are on another sheet.
I want to generate an invoice containing everything that the customer has ordered. The code I have currently lists only the final row of the "results" array into my template sheet. I want all of the items that the customer ordered to be added to the invoice. I'm trying to figure out how to use "index" to move to the next line and add the next set of values, but I'm not sure what I'm doing wrong. By logging info, I see that everything is being called correctly and adding to the correct spot in the template. The problem is that it only adds the final line of data into the template when I want all of the lines that match a customer's name.
I have some values in array like this below (arr1);
I need to make a kind of unique arrayList which has to collect and make a new list with values before "~"
If the value before the "~" is in the new list, the value after "~" has to append into existing value of array.
var arr1:Array = new Array();
arr1[0] = "test 1 ~ 781.102";
arr1[1] = "test 2 ~ 981.112";
arr1[2] = "test 2 ~ 191.222";
arr1[3] = "~ 431.332";
arr1[4] = "test 1 ~ 121.332";
arr1[5] = "test 3 ~ 121.442";
arr1[6] = "test 3 ~ 201.552";
New List should be this...
var nArr:Array = new Array();
nArr[0]= "test 1 - (781.102,121.332)";
nArr[1]= "test 2 - (981.112,191.222)";
nArr[2]= "test 3 - (121.442,201.552)";
nArr[3]= "undefined - (431.332)";
Use .split("~") to separate substrings divided by ~. The result is an array.
Use a JavaScript object with keys and values. The key is "test 1", "test 2", ... and the value is a JavaScript array. Add for every element of arr1 the number to array for the given key.
Finally, create an array from your object and convert the array values into "( ..., ...)"
Your code would look like this:
var obj = {};
for (var i = 0; i < arr1.length; i++) {
var keyAndValue = arr1[i].split("~");
var key = keyAndValue[0].trim();
var value = keyAndValue[1].trim();
var array = [];
if (key in obj) {
array = obj[key];
}
array.push(value);
obj[key] = array;
}
var nArr = [];
for (key in obj) {
nArr.push(key + " - (" + obj[key].toString() + ")");
}
What you're using are not ArrayLists, they're Arrays.
To avoid reinventing a wheel, search the web for java.util.ArrayList if you want best practice on how to manipulate an ArrayList.
The best advice is to use Java constructs rather than SSJS Arrays. They are documented more widely on the web (because they're used beyond just XPages) and will get you used to handling these kinds of things in Java business logic in the future. Look at Lists and Sets and Maps.
What you're actually wanting is not a unique list, it's a Map of unique values (to the left of a tilde) followed by a concatenated string of entries that use that key.
I have generated a number and sent it to a text box. Now I want to save that number for later use. Arrays seem (to my very limited knowledge) to be the place to keep data you wish to access later on. How do I do this?
my code so far:
roll_btn.addEventListener (MouseEvent.CLICK, rollDice);
function rollDice (Event:MouseEvent):void{
var die1:uint = Math.floor (Math.random()* 6) + 1;
var die2:uint = Math.floor (Math.random()* 6) + 1;
die1_txt.text = die1.toString();
die2_txt.text = die2.toString();
sec1_txt.text = (die1 + die2).toString();
}
I want to add the result in "sec1_txt.text" to an array.
Thanks in advance.
Use this:
var myArray:Array = new Array();
myArray.push(die1 + die2)
You can also use a Vector that is a typized (of uint) array.
I would like to put all my coordinates into an array and have a loop display each one but with a Google function.
Here's the code, which draws the points on google map:
var flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
];
I would like to be able to do something like this:
var arrPos = new Array([37.772323, -122.214897], [21.291982, -157.821856], [-18.142599, 178.431], etc. );
var flightPlanCoordinates = [ +
for (i=0; i<arrPos.length; i++){
new google.maps.LatLng(arrPos[0]) + ", "
}
+ "];"
I know you can put a loop in an array but is there an alternate method to retrieving the points from the array??
tks
Like this:
For(var i in arrPos){
new google.maps.LatLng(arrPos[i][0],arrPos[i][1]);
}
Greets
Thomas van Latum
I'm not sure whether there is a simply answer to this but I am assuming there isn't, hence I'm here.
Basically, I want to run a very simple high score table which keeps track of the high scores of a game, but also displays the correct names beside each scores.
This is all easy but I want to be able to do this with just the one array.
For example, I have this code:
var d:Array;
var e:Array;
d = "827-Harry".split("-");
d.push("918-John".split("-"));
trace(d)
Which correctly results this trace:
827,Harry,918,John
My question is, how can I use Array.sort() (or similar) in such a way that the following is produced:
d = 918, John, 827, Harry
It can't be specific to this example. That is, it needs to work with custom names and dynamic scores.
Cheers in advance!
Harry.
create an associative array and use sortOn():
var highscores:Array = new Array();
highscores.push({score: 827, player: "John"});
highscores.push({score: 918, player: "Harry"});
highscores.sortOn("score", Array.DESCENDING | Array.NUMERIC);
for (var i:int = 0; i < highscores.length; i++)
{
trace(highscores[i].score, highscores[i].player);
}
Wouldn't recommend you store your high scores like that but I don't know your reasons so here's exactly how to do what you want.
public function sortArray(arrUnsorted:Array):Array
{
var arrLocal:Array = new Array();
var arrSorted:Array = new Array();
for (var i:int = 0; i < arrUnsorted.length; i += 2)
{
arrLocal.push( { score:int(arrUnsorted[i]), name:arrUnsorted[i + 1] } );
}
arrLocal.sortOn("score", Array.DESCENDING | Array.NUMERIC)
for each(var obj:Object in arrLocal)
{
arrSorted.push(String(obj.score), obj.name);
}
return arrSorted;
}
Then it's as simple as:
var arrUnsorted:Array = ["827", "Harry", "918", "John"];
var arrSorted:Array = sortArray(arrUnsorted);
trace(arrSorted); // 918,John,827,Harry
Hope this is what you're after.