hey guys
I followed a tut online and got code for an anagram elearning game.
I would like to try and add more elements to it.I would like to associate the anagram word with the corresponding picture when the game plays how would i go about doing that here is the code from the main game class any help would be great.
Code:
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;
public class Game extends MovieClip {
var words:Array = new Array; //a mini database to hold the words
var rand1:int;var rand2:int; //variables used for randomization
var i:int; //variable used for loop iterations
var ii:int;
var ques_num:int; //used to track the question number
var current_word:String; //used to hold the current word being tested
var user_ans:String; //used to hold the user's answer
var tileArray:Array = new Array; //array of tile objects
var targetArray:Array = new Array; //array of target areas
var scramble_Array:Array = new Array; //array used to scramble the word
var unscramble_Array:Array = new Array; //array to hold the unscrambled word
var temp:String; //temporary variable
var flag:Boolean; //flag variable
var checker:button_chk; //CHECK button
var f1:feedback1; //feedback boxes 1 - 3
var f2:feedback2;
var f3:feedback3;
var pauser:Boolean; //used to pause the game
public function Game() {
getword();
checker=new button_chk;addChild(checker);
checker.x=150;checker.y=400;
checker.addEventListener(MouseEvent.CLICK, check_answer);
}
public function getword() {
words=["car ","dog" ,"tree"];
current_word=words[ques_num];
setTiles(current_word.length);
ques_num++;
}//getword
public function setTiles(a) {tileArray=[ ];
for(i=0;i<a;i++){
var tempclip:Tile =new Tile;addChild(tempclip);
tempclip.x=100+(i*60);tempclip.y=200;tempclip.tag=i;
tempclip.original_posx=tempclip.x;
tempclip.original_posy=tempclip.y;
tileArray[i]=tempclip;
var tempclip2:Placeholder =new Placeholder;addChild(tempclip2);
tempclip2.x=100+(i*60);tempclip2.y=280;
targetArray[i]=tempclip2;
}//for i
scramble_word(a);
}//setTiles
public function scramble_word(a) {
for(i=0;i<a;i++){scramble_Array[i]=current_word.slice(i,i+1)}
for(i=0;i<15;i++){
rand1=Math.ceil(Math.random()*(a))-1;
rand2=Math.ceil(Math.random()*(a))-1;
temp=scramble_Array[rand1];scramble_Array[rand1]=scramble_Array[rand2];scramble_Array[rand2]=temp;}
for(i=0;i<a;i++){tileArray[i].letter.text=scramble_Array[i];}
addListeners(a);
}//scramble_word
public function addListeners(a){
for(i=0;i<a;i++){
tileArray[i].mouseChildren = false;
tileArray[i].addEventListener(MouseEvent.MOUSE_DOWN, pickup);
tileArray[i].addEventListener(MouseEvent.MOUSE_UP, drop);
}//fori
}
public function pickup(event:MouseEvent){
if(!pauser){
event.target.startDrag(true);
this.setChildIndex(MovieClip(event.target),this.numChildren-1);
}//pauser
}//pick up
public function drop(event:MouseEvent) {
event.target.stopDrag();
flag=false;trace(event.target);
for(i=0;i<targetArray.length;i++){
if(targetArray[i].hitTestObject(event.target)){event.target.x=targetArray[i].x;event.target.y=targetArray[i].y;flag=true;}
}//for i
for(i=0;i<tileArray.length;i++){
if((tileArray[i].hitTestObject(event.target))&&(tileArray[i]!=event.target)){flag=false;}
}//for i
if(!flag){event.target.x=event.target.original_posx;event.target.y=event.target.original_posy;}
}//drop
public function check_answer(e:MouseEvent) {
if(!pauser){
user_ans="";
for(i=0;i<targetArray.length;i++){for(ii=0;ii<tileArray.length;ii++){
if((tileArray[ii].x==targetArray[i].x)&&(tileArray[ii].y==targetArray[i].y)){user_ans+=tileArray[ii].letter.text;}
}}//end of nested loop
if(user_ans==current_word){f1=new feedback1;addChild(f1);f1.x=100;f1.y=100;pauser=true;
f1.addEventListener(MouseEvent.CLICK, clear_board);
}
else{f2=new feedback2;addChild(f2);f2.x=100;f2.y=100;pauser=true;
f2.addEventListener(MouseEvent.CLICK, continue_on);
}
}
}//check_answer
public function continue_on(e:MouseEvent) {
f2.removeEventListener(MouseEvent.CLICK, continue_on);
removeChild(f2);
pauser=false;
}//clear_board
public function clear_board(e:MouseEvent) {
f1.removeEventListener(MouseEvent.CLICK, continue_on);
removeChild(f1);
pauser=false;
for(i=0;i<tileArray.length;i++){removeChild(tileArray[i]);removeChild(targetArray[i]);}
if(ques_num==words.length){removeChild(checker);f3=new feedback3;addChild(f3);f3.x=100;f3.y=100;}else{getword();}
}//clear_board
}
}