Hi, I am trying to create a simple flashcard script using arrays. I have gotten pretty far, but I can't get the function right to forward to the next question in the flash card array. The function to go back works fine. I originally wrote it in javascript, and transfered it into as3. Here is my code:
Code:import km.core.*; import km.components.*; //flashcards array var cards = [ ['card1', 'answer1'], ['card2', 'answer2'], ['card3', 'answer3'] ]; var i = 0; txt2.text = cards[i][0]; var back:LabelButton = new LabelButton; var forward:LabelButton = new LabelButton; var flip1:LabelButton = new LabelButton; var flip2:LabelButton = new LabelButton; ScriptedSkin.applyTo(back,forward,flip1,flip2); back.setSize(90,24); back.move(114,30); back.label.text = '<< Back'; forward.setSize(90,24); forward.move(424,30); forward.label.text = 'Next >>'; flip1.setSize(90,24); flip1.move(275,30); flip1.label.text = 'Show'; flip2.setSize(90,24); flip2.move(275,30); flip2.label.text = 'Hide'; addChild(back); addChild(forward); addChild(flip1); back.onClick = function() { //this works fine navigating the array i = (i == 0) ? cards.length-1 : i-1; txt2.text = cards[i][0]; //clear answer area txt1.text = ""; } forward.onClick = function() { //for some reason, this doesn't work i = (i == cards.length-1) ? 0 : i+1; txt2.text = cards[i][0]; } flip1.onClick = function() { txt1.text = cards[i][1]; } }




Reply With Quote