Hello and thank you for your time. I have an as3 code which randomly picks 5 frames out of 7, no repeats.
var mygroup1:RadioButtonGroup = new RadioButtonGroup("group1");
q1a1.group = q1a2.group = q1a3.group = q1a4.group = q1a5.group = mygroup1;
var number_array:Array = [8158,8159,8160,8161,8162,8163,8164];
var final_array:Array = [];
var count_selected:int = 5;
var i:int;
for(i = 0; i < count_selected; i++)
{
if(number_array.length == 0)
break;
else
final_array.push(number_array.splice(Math.floor(Math.random() * number_array.length), 1)[0]);
}
var index = 0;
var currentQuestion:int = final_array[index];
var answers:Object = {
8158: 'B) 12',
8159: 'F) All of the above',
8160: 'A) True',
8161: 'B) False',
8162: 'C) 4',
8163: 'F) D and E',
8164: 'B) B'
};
var getAnswer = mygroup1.selection.label; //Getting the selection from RadioButtonGroup
submitBtn.addEventListener(MouseEvent.CLICK, onSubmitClicked);
function onSubmitClicked(e:MouseEvent):void {
var answer:String = getAnswer();
if (answer === answers[currentQuestion])
awardScore(currentQuestion);
++index;
currentQuestion = final_array[index];
gotoAndStop(final_array[index]);
}
and when you click on the "startBtn", it takes you to the first randomly generated frame(final_array[0]) and it's all great to start the process randomly.
Each of the next 7 frames has a submit button(b1,b2...b7) which keeps track of the score and submits the answer and also should go to the next randomly picked frame but only 5 times, following the remaining generated frames....gotoAndStop(final_array[1])...(final_array[2])....(final_array[3])....(final_array[4]).
b1.addEventListener(MouseEvent.CLICK, quizHandler1)
function quizHandler1(event:MouseEvent):void{
if(mygroup1.selection.label=="B) 12") {
count = count + 20;
scoreresult.text = (count).toString();
gotoAndStop(final_array[1]);
}
else{
gotoAndStop(final_array[1]);
}
}
My problem is...Since the user will only go to 5 randomly picked frames out of 7, how can I make sure all the buttons in all 7 frames will listen and follow the gotoAndStop(final_array[]); statement in the order of 5? Because at the end, 2 frames will be left out, and those two frames will change randomly in every roll. I hope I could explain my dilemma. Thank you again.
To do a quiz like yours, I think that you don't need to duplicate all content on every frame. You can put your questions in MovieClips ( or one MovieClip with many frames ) and then you can add it to your stage, and for your check box you can create it once and every time you can change just their values and labels. For buttons, you need only one button which will validate and check the current question and the go to the next one.
Take a look on this example :
var score:int;
var max_score:int;
const default_score:int = 20;
// create our questions list (7 questions) :
var questions_list:Object = {
// index : to identify our question
// movie_clip : the class name used for AS linkage
1: { index : 1, movie_clip : Question1, good_answer : 'css3', first_answer : 'html5', second_answer : 'jquery', third_answer : 'css3', score : default_score },
2: { index : 2, movie_clip : Question2, good_answer : 'html5', first_answer : 'html5', second_answer : 'less', third_answer : 'ruby', score : 50 },
3: { index : 3, movie_clip : Question3, good_answer : 'jquery', first_answer : 'ruby', second_answer : 'jquery', third_answer : 'css3', score : default_score },
4: { index : 4, movie_clip : Question4, good_answer : 'less', first_answer : 'less', second_answer : 'html5', third_answer : 'css3', score : 15 },
5: { index : 5, movie_clip : Question5, good_answer : 'nodejs', first_answer : 'python', second_answer : 'nodejs', third_answer : 'jquery', score : 10 },
6: { index : 6, movie_clip : Question6, good_answer : 'python', first_answer : 'css3', second_answer : 'html5', third_answer : 'python', score : default_score },
7: { index : 7, movie_clip : Question7, good_answer : 'ruby', first_answer : 'ruby', second_answer : 'html5', third_answer : 'less', score : default_score }
};
var enabled_questions:Array = [1, 2, 3, 4, 5, 6, 7];
var current_question:int = 0;
//----------------------------------------------------------------------------------------------------
// sprite that shows our questions
var questions_container:Sprite = new Sprite();
questions_container.x = questions_container.y = 20;
questions_container.visible = false;
addChild(questions_container);
var checks_group:RadioButtonGroup = new RadioButtonGroup('checks_group');
// sprite that contains our 3 check box
var checks_container:Sprite = new Sprite();
checks_container.visible = false;
checks_container.x = int(stage.stageWidth / 2);
checks_container.y = 50;
addChild(checks_container);
// create our check box, 3 buttons in my case
// the 4th one is used only to uncheck every time all check box
for(var i:int = 0; i < 4; i++)
{
var btn_check:RadioButton = new RadioButton();
if(i != 3){
btn_check.y = i * 30;
} else {
// our 4th check box is hidden
btn_check.visible = false;
}
btn_check.group = checks_group;
btn_check.name = 'btn_check' + i;
checks_container.addChild(btn_check);
}
// start button
var btn_start:Button = new Button();
btn_start.label = 'Start ! ';
btn_start.width = 180;
btn_start.height = 60;
btn_start.x = int((stage.stageWidth - btn_start.width)/2);
btn_start.y = int((stage.stageHeight - btn_start.height)/2) - 20;
btn_start.addEventListener(MouseEvent.CLICK, startQuiz);
addChild(btn_start);
// next button, to go to the next question
var btn_next:Button = new Button()
btn_next.label = 'Next >> ';
btn_next.width = 90;
btn_next.height = 30;
btn_next.visible = false;
btn_next.x = stage.stageWidth - btn_next.width - 10;
btn_next.y = stage.stageHeight - btn_next.height - 10;
btn_next.addEventListener(MouseEvent.CLICK, checkAnswer);
addChild(btn_next);
// a text field which will show the score and the current question number
var txt_score:TextField = new TextField();
txt_score.width = 200;
txt_score.height = 30;
txt_score.x = stage.stageWidth - txt_score.width;
txt_score.y = 10;
txt_score.visible = false;
txt_score.selectable = false;
addChild(txt_score);
//----------------------------------------------------------------------------------------------------
function startQuiz(e:MouseEvent):void
{
// here we will get only 5 questions
// I used a method from http://stackoverflow.com/questions/11980657/as3-random-array-randomize-array-actionscript-3 to shuffle the array
// and then I remove the last 2 elements from the array
enabled_questions = enabled_questions.sort(function(i:*,j:*){return(Math.random()<.5)?-1:1;}).slice(0,enabled_questions.length-2);
for(var i:int = 0; i < enabled_questions.length; i++){
var q_i:int = enabled_questions[i];
var q:Object = questions_list[q_i];
max_score += q.score;
// create our questions instance and hide it
// every question is an instance of a movieclip in our library
// we can alse use only one movieclip and then we can use its timeline to go from a question to another
var question = new (q.movie_clip);
question.index = q_i;
question.visible = false;
questions_container.addChild(question);
}
// hide the start button
e.target.visible = false;
// show other elements
questions_container.visible = checks_container.visible = btn_next.visible = txt_score.visible = true
// load the first question
loadQuestion(current_question);
}
// check the answer and update score
function checkAnswer(e:MouseEvent):void
{
var question:Object = questions_list[enabled_questions[current_question]];
if(question.good_answer == checks_group.selectedData){
// update the score
setScore(question.score);
}
if(current_question < enabled_questions.length - 1){
current_question ++;
loadQuestion(current_question);
} else {
e.target.x = e.target.y = 0;
e.target.enabled = false;
e.target.width = stage.stageWidth;
e.target.height = stage.stageHeight;
e.target.label = 'You have finished the quiz, your score is : ' + score;
checks_container.visible = questions_container.visible = txt_score.visible = false;
}
}
// load question (show it) and update our check box
function loadQuestion(index:int):void
{
var question:Object = questions_list[enabled_questions[index]];
for(var i:int = 0; i < checks_container.numChildren; i++){
if(checks_container.getChildAt(i) is RadioButton){
var btn:RadioButton = RadioButton(checks_container.getChildAt(i));
switch (btn.name){
case 'btn_check0' : btn.value = btn.label = question.first_answer; break;
case 'btn_check1' : btn.value = btn.label = question.second_answer; break;
case 'btn_check2' : btn.value = btn.label = question.third_answer; break;
case 'btn_check3' : btn.selected = true; break;
}
}
}
for( i=0; i < questions_container.numChildren; i++){
if(questions_container.getChildAt(i) is MovieClip){
var mc:MovieClip = MovieClip(questions_container.getChildAt(i));
mc.visible = mc.index == question.index;
}
}
// setScore is used here just to update the question number in the score text field
setScore();
}
// show the score and current question
function setScore(new_score:int = 0){
score += new_score;
txt_score.text = 'Score : ' + score.toString() + ' / ' + max_score.toString() + ', Question : ' + (current_question+1) + ' / ' + enabled_questions.length;
}
// icons used in this example by Jozef Krajčovič : https://www.iconfinder.com/Jozef89
This code gives you something like this :
You can also see it working here.
Of course this is just a simple example, you can improve and adapt it to your needs.
Hope that can help.
Sounds like you just need a single submit button that goes to the next frame. That way you don't have to worry about the order.
Some sample code to give you an idea how it might work
var index = 0;
var currentQuestion:int = final_array[index];
var answers:Object = {
8158: '12',
8159: '13'
//...etc.
};
submitBtn.addEventListener(MouseEvent.CLICK, onSubmitClicked);
function onSubmitClicked(e:MouseEvent):void {
var answer:String = getAnswer(); //get the user's answer
if (answer === answers[currentQuestion]) {
awardScore(currentQuestion);
++index;
currentQuestion = final_array[index];
gotoAndStop(final_array[index]);
}
}
The idea is to have all that logic in a single click handler, once clicked it will grab the users answer and check if it is correct, if it is then it goes on to the next question.
Related
I am trying to create an array of sizes. I am adding to the array just fine and it is displaying. I try to remove with .pop(); and it gives me the error listed in the title of this post.
this.add = function(item, id, size){
var storedItem = this.items[id];
if(!storedItem) {
storedItem = this.items[id] = {item: item, qty: 0, price: 0, size: []}. <------
}
storedItem.size += size;
storedItem.qty++;
storedItem.price = storedItem.item.price * storedItem.qty;
this.totalQty++;
this.totalPrice += storedItem.item.price;
}
this.reduceByOne = function(id){
this.items[id].size.pop(). <------------
this.items[id].qty--;
this.items[id].price -= this.items[id].item.price;
this.totalQty--;
this.totalPrice -= this.items[id].item.price;
if(this.items[id].qty <= 0) {
delete this.items[id];
}
}
I have also tried this and get the same error.
var reduceOne = this.items[id].size;
reduceOne.pop();
storedItem.size += size;
Did you mean to use push here instead of +=?
storedItem.size.push(size);
In AS3 :
I've got a long text in an array.
var myHugeArray:Array = ["I love Apple
I have an Iphone
I eat a Banana
I'm John
I sell a computer
I sell an Apple
I love rock
I sell a car"];
How can I do to search a specifics words ? (like : show me sentences with the word "apple") --> output : "I love Apple" and "I sell an Apple"
Thanks,
EDIT
Here's what I did so far :
loader5.load(urlReq);
loader5.addEventListener(Event.COMPLETE,completeHandler2);
function completeHandler2(event:Event):void{
loader5.removeEventListener(Event.COMPLETE,completeHandler2);
trace("Données envoyées");
feedbackText.text = "Données envoyées";
loader5.load(urlReq);
loader5.addEventListener(Event.COMPLETE, complete);
}
function complete(e:Event):void {
addChild(list);
products = JSON.parse(loader5.data) as Array;
feedbackText.text = "complete";
for(var i:int = 0; i < products.length; i++){
createListItem(i, products[i]);
}
showList();
}
function createListItem(index:int, item:Object):void {
var listItem:TextField = new TextField();
listItem.text = item.title;
listItem.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
showDetails(item);
});
list.addChild(listItem);
str = item.title;
bar();
}
function bar(){
var arr: Array ;
searchBar.type = TextFieldType.INPUT;
var suggested:Array = new Array();
var textfields:Array = new Array();
searchBar.addEventListener(Event.CHANGE, suggest);
arr = str.split(",");
trace(arr);
function suggest(e:Event):void
{
suggested = [];
for (var i:int = 0; i < textfields.length; i++)
{
removeChild(textfields[i]);
}
textfields = [];
for (var j:int = 0; j < arr.length; j++)
{
if (arr[j].indexOf(searchBar.text.toLowerCase()) != -1)
{
var term:TextField = new TextField();
term.width = 360;
term.height = 24;
term.x = 18;
term.y = (24 * suggested.length) + 135;
term.border = true;
term.borderColor = 0x353535;
term.background = true;
term.backgroundColor = 0xFF9900;
term.textColor = 0x4C311D;
term.defaultTextFormat = format;
addChild(term);
suggested.push(arr[j]);
term.text = arr[j];
}
}
function showList():void {
list.visible = true;
}
function showDetails(item:Object):void {
titleTxt.htmlText = item.title;
detailsTxt.htmlText = "<U>prix:</U> " + item.prix + " xpf"+ "\n\n<U>Description:</U> " + "\n"+item.theDescription + "\n"+"\n\n<U>Contact:</U> " + item.mail+ "\n"+item.phone;
}
So, my AS3 code go search for PHP variable with loader5.
All the items found by the php are put in an Array (products).
And a list of all the products is created. (createListItem).
If I click on an item, it show me some details (price, description..etc). It's the function showDetails();
Know I've created a searchBar (autocomplete).
An array is created (arr) that split the string (str).
Then it does what it does to search through the array.
Problems :
1/ Weirdly, not all the words are displayed in my searchBar. Some words are working, other not.
2/ How can I do to call the function showDetails() when the user click on the suggest term ? (term.addEventListener(MouseEvent.CLICK, showDetails)); doesn't work as the terms is not item.title. ShowDetails is showing details of item.title. (so how can I say that term = item.title ?)
3/ Do you see a way simpler than that ?
Your myHugeArray is just string, so split() it with \n', you got the
ret array for example, then find the one contains the word you search, like "apple", using indexof() in each string
You need to split the string into an array then search each item
check this out
https://stackoverflow.com/a/34842518/3623547
I have this code in my simple flash. I want to save name and score in my quiz. My code reference in this website http://www.mollyjameson.com/blog/local-flash-game-leaderboard-tutorial/
I want to make my code in just one actionscript. But I didn't success do it.
var m_FlashCookie = SharedObject.getLocal("LeaderboardExample");
var EntryName:String ="nama kamu";
var EntryScore:String ="nilai";
const NUM_SCORES_SAVED:int = 10;
inputBoxScore.text = EntryScore;
inputBoxName.text = EntryName
var latest_score_object:Object = {
name: EntryName,
score: EntryScore
};
var arr:Array;
arr = m_FlashCookie.data.storedArray
if ( arr == null)
{
arr = new Array();
}
arr.push( latest_score_object );
arr.sortOn("score", Array.NUMERIC | Array.DESCENDING);
if ( arr.length < NUM_SCORES_SAVED )
{
arr.pop();
}
btnSave.addEventListener(MouseEvent.CLICK, saveData);
function saveData(event:Event):void
{
m_FlashCookie.data.arr = arr;
m_FlashCookie.flush();
}
var myHTMLL:String = "";
var total_stored_scores:int = arr.length;
btnLoad.addEventListener(MouseEvent.CLICK, loadData);
function loadData(event:Event):void
{
for (var i:int = 0; i < total_stored_scores; ++i)
{
// loop through every entry, every entry has a "name" and "score" field as that's what we save.
var leaderboard_entry:Object = arr[i];
// is this the last score that was just entered last gamestate?
if ( leaderboard_entry == latest_score_object )
{
myHTMLL += (i+1) + ". <b><font color=\"#0002E5\">"+ leaderboard_entry.name + " " + leaderboard_entry.score +"</font></b><br>";
}
else
{
myHTMLL += (i+1) + ". "+ leaderboard_entry.name + " " + leaderboard_entry.score +"<br>";
}
}
myHTML.text = myHTMLL;
}
Can anybody help me?
You're saving the array as data.arr but reading the array as data.storedArray. You need to make them the same.
In other words, you've written this:
m_FlashCookie.data.arr = arr;
And when you load:
arr = m_FlashCookie.data.storedArray;
This clearly doesn't make sense: data.storedArray is never set, so it will never have a value, so you will always end up with a new empty array.
You need to use the same property on the shared object data. For example:
m_FlashCookie.data.storedArray = arr;
m_FlashCookie.flush();
Looking at your code, there's a number of other issues:
The latest score is immediately removed because arr.length < NUM_SAVED_SCORES is going to be true from the start, since arr starts out empty, and it then calls arr.pop() which will remove the latest entry that was just added. So the array is always empty.
It adds the score immediately with arr.push(latest_score_object) instead of waiting until the user clicks save, so the value of the input texts don't matter at all -- the saved values will always be "nama kamu" and "nilai".
The following fixes all the issues mentioned:
var leaderboard = SharedObject.getLocal("leaderboard");
const MAX_SAVED_SCORES:int = 10;
inputBoxName.text = "nama kamu";
inputBoxScore.text = "nilai";
var entries:Array = leaderboard.data.entries || [];
var latestEntry:Object;
displayScores();
btnLoad.addEventListener(MouseEvent.CLICK, loadClick);
btnSave.addEventListener(MouseEvent.CLICK, saveClick);
function loadClick(e:MouseEvent):void {
displayScores();
}
function saveClick(e:MouseEvent):void {
saveLatestScore();
displayScores();
}
function saveLatestScore():void {
// create the latest entry based on input texts
latestEntry = {
name: inputBoxName.text,
score: inputBoxScore.text
};
// add the entry and sort by score, highest to lowest
entries.push(latestEntry);
entries.sortOn("score", Array.NUMERIC | Array.DESCENDING);
// if reached the limit, remove lowest score
if (entries.length > MAX_SAVED_SCORES) {
entries.pop();
}
// store new sorted entries to shared object
leaderboard.data.entries = entries;
leaderboard.flush();
}
function displayScores():void {
var myHTMLL:String = "";
for (var i:int = 0; i < entries.length; ++i) {
// loop through every entry, every entry has a "name" and "score" field as that's what we save.
var entry:Object = entries[i];
// is this the last score that was just entered last gamestate?
if (entry == latestEntry)
myHTMLL += (i+1) + ". <b><font color=\"#0002E5\">"+ entry.name + " " + entry.score +"</font></b><br/>";
else
myHTMLL += (i+1) + ". "+ entry.name + " " + entry.score +"<br/>";
}
myHTML.htmlText = myHTMLL;
}
I'm making a game currently for fun, and wanted to use arrays to draw levels with.
However, it seems there is some error that stops the program from actually drawing the rectangles. I've looked for pretty much every error that I could think of in the code. I've even tried re-learning the array subject on KhanAcademy, but nothing there seems to fix my problem. So I thought that StackOverflow was my last resort. You can see the game here, or if you just wanna see the pure code, it can be found here, and if you think my site will give you a virus, you can just see it here:
var sketchProc = function(processingInstance) {
with (processingInstance) {
size(400, 400);
frameRate(60);
// Setup stuff 'n stuff
noStroke();
fill(0, 0, 0);
var scene = 0;
var controlsEnable = 0;
var tufdasDebug = 0;
var tufdasLeve;
/* Key/control variables (JavaScript key codes:
http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes)*/
var keyIsPressed = 0;
var key_SHIFT = 16;
var key_CTRL = 17;
// Position & Size variables
var jumperXPos = 100;
var jumperYPos = 360;
var jumperSize = 20;
// Counters
var jumperXCounter = 11;
var jumperYCounter = 11;
var shiftCounter = 11;
keyPressed = function() {
keyIsPressed = 1;
};
keyReleased = function() {
keyIsPressed = 0;
resetCounters();
};
var askForResolution = function() {
text("What resolution do you want to play in?", 100, 15);
};
var addCounters = function(amount) {
if (amount) {
jumperXCounter += amount;
jumperYCounter += amount;
shiftCounter += amount;
} else {
jumperXCounter ++;
jumperYCounter ++;
shiftCounter ++;
}
};
var resetCounters = function() {
jumperXCounter = 11;
jumperYCounter = 11;
shiftCounter = 11;
};
var controlsHandler = function() {
addCounters();
if (tufdasDebug === 1) { console.log("Handling controls..."); }
if (keyIsPressed === 1) {
if (tufdasDebug === 1) { console.log("A key is being pressed..."); }
if (controlsEnable === 0) {
if (tufdasDebug === 1) { console.log("Controls disabled..."); }
if (keyCode === key_SHIFT) {
if (tufdasDebug === 1) { console.log("Shift is being pressed."); }
scene ++;
controlsEnable = 1;
}
} else if (controlsEnable === 1) {
if (keyCode === UP && jumperYCounter > 10) {
jumperYPos -= 20;
jumperYCounter = 0;
} else if (keyCode === RIGHT && jumperXCounter > 10) {
jumperXPos += 20;
jumperXCounter = 0;
}
}
}
};
var drawIntroSequence = function(y) {
textSize(30);
text("JUMPER", 125, y + 100);
textSize(15);
text("Press SHIFT or RSHIFT to continue...\n(make sure to click inside the game first)", 65, y + 300);
};
var drawJumper = function() {
fill(0, 0, 255);
rect(jumperXPos, jumperYPos, jumperSize, jumperSize);
};
var drawtufdasLevel = function() {
fill(0, 0, 0);
rect(tufdasLevel[0], tufdasLevel[1], tufdasLevel[2], tufdasLevel[3]);
rect(tufdasLevel[4], tufdasLevel[5], tufdasLevel[6], tufdasLevel[7]);
};
draw = function() {
background(255, 255, 255);
if (scene === 0) {
drawIntroSequence(0);
var tufdasLevel = [0, 380, 400, 20, 0, 0, 400, 20]; // Space indicates a new command.
} else if (scene === 1) {
drawtufdasLevel();
drawJumper();
}
controlsHandler();
};
}};
var canvas = document.getElementById("tufdaDrawCanvas");
var processingInstance = new Processing(canvas, sketchProc);
To figure out exactly what's happening, open up your JavaScript console by opening your game in a browser, pressing the F12 key, and then going to the "Console" tab.
When your game starts, you'll see the error:
Uncaught TypeError: Cannot read property '0' of undefined at game.js:100
That tells you the error is happening on line 100 of your sketch, which is this line:
rect(tufdasLevel[0], tufdasLevel[1], tufdasLevel[2], tufdasLevel[3]);
So now you know something is wrong with your tufdasLevel variable. Let's see where you declare it. You've got one here on line 12:
var tufdasLevel;
That's your declaration, but where is your initialization? You've got one here, one line 118:
var tufdasLevel = [0, 380, 400, 20, 0, 0, 400, 20]; // Space indicates a new command.
Ah-ha! Notice how you're using the var keyword to declare another variable named tufdasLevel. This is a different variable from the one at the top of your sketch, which is the one being used on line 100. The tufdasLevel variable on line 118 is never used, and the tufdasLevel on line 12 is never initialized. So when your game tries to use that uninitialized variable, you get the error you're seeing.
It seems like you meant to initialize the variable on line 118, not declare it. Try just dropping the var keyword from line 118:
tufdasLevel = [0, 380, 400, 20, 0, 0, 400, 20]; // Space indicates a new command.
You might also put that initialization on line 12 instead.
There is a multi-d array and I want to reach specific field in it. I have look around it but I was unable to find proper answer to my question.
My array is like that;
array-md
columns-- 0 | 1 | 2
index 0 - [1][John][Doe]
index 1 - [2][Sue][Allen]
index 2 - [3][Luiz][Guzman]
.
.
.
index n - [n+1][George][Smith]
My question is how can I reach only second column of the array? I tried name = array[loop][1]; but it says "Cannot access a property or method of a null object reference". What is the right way to do that?
Here is main part of the code.
get
var lpx:int;
var lpxi:int;
var arrLen:int = Info.endPageArray.length;
for(lpx = 0; lpx < arrLen; lpx++)
{
for(lpxi = Info.endPageArray[lpx][2]; lpxi < Info.endPageArray[lpx][1]; lpxi++)
{
if(Info._intervalSearch[lpxi] == "completed")
{
successCount++;
Info._unitIntervalSuccess.push([lpx, successCount / (Info._intervalSearch.length / 100)]);
}
}
}
set
for(lpix = 0; lpix < arrayLength; lpix++)
{
if(lpix + 1 <= arrayLength)
{
Info.endPageArray.push([lpix, Info._UnitsTriggers[lpix + 1], Info._UnitsTriggers[lpix]]);
}
else
{
Info.endPageArray.push([lpix, Info._UnitsTriggers[lpix], Info._UnitsTriggers[lpix - 1]]);
}
}
Try this:
var tempArr:Array = [];
function pushItem(itemName:String, itemSurname:String):void
{
var tempIndex:int = tempArr.length;
tempArr[tempIndex] = {};
tempArr[tempIndex][tempIndex + 1] = {};
tempArr[tempIndex][tempIndex + 1][name] = {};
tempArr[tempIndex][tempIndex + 1][name][itemSurname] = {};
}
function getNameObject(index:int):Object
{
var result:Object;
if(index < tempArr.length)
{
result = tempArr[index][index + 1];
}
return result;
}
pushItem("Max", "Payne");
pushItem("Lara", "Croft");
pushItem("Dart", "Vader");
//
trace(getNameObject(0));
trace(getNameObject(1));
trace(getNameObject(2));
Multidimensional array is an array of arrays, which you can create like this :
var persons:Array = [
['John', 'Doe'],
['Sue', 'Allen'],
['Luiz','Guzman']
];
var list:Array = [];
for(var i:int = 0; i < persons.length; i++)
{
list.push([i + 1, persons[i][0], persons[i][1]]);
}
trace(list);
// gives :
//
// 1, John, Doe
// 2, Sue, Allen
// 3, Luiz, Guzman
Then to get some data :
for(var j:int = 0; j < list.length; j++)
{
trace(list[j][1]); // gives for the 2nd line : Sue
}
For more about multidimensional arrays take a look here.
Hope that can help.