tryin_to_learn
06-01-2005, 06:27 PM
I'm working on a scrambled word game. I've written 4 functions, one to randomize, one to place the instances of the letters in the scrambled word; one to place target movie clips(will not show on the stage); and the forth places the lines to drag the scrambled letters to. I'm trying to figure out how to do a hitTest so I can indicate if someone drags a letter into the correct position. I've got an if statement at the very bottom of the code below that finds the matching pairs. However, it's working by using charAt, which means that we're comparing strings. How do I target the clips that are holding those strings? Here's the code:
function rand() {
return random(3)-1;
}
words_arr = new Array('POND', 'BUGS', 'ANIMALS', 'PLANTS', 'SWAMP', 'INSECTS', 'FROGS', 'ANTS', 'MOSQUITOS');
randomIncr = Math.floor(Math.random() * words_arr.length);
randomWord = String(words_arr[randomIncr]);
wordCorrectOrder = randomWord.split("").join("");
shuffledWord=randomWord.split("").sort(rand).join("");
function placeLines () {
for(var i = 0; i < shuffledWord.length; i++){
this.attachMovie("mcTargetSymbol", "line_mc" + i, this.getNextHighestDepth());
targetLine = this["line_mc"+i];
}
}
function placeTargetClips () {
for(var i = 0; i < shuffledWord.length; i++){
this.attachMovie("targetLetterSY","targetWord_" + i, this.getNextHighestDepth());
targetLetterClip = this["targetWord_" + i];
targetLetterClip.target_letter.text = wordCorrectOrder.charAt(i);
}
}
function placeScrambledLetters () {
for(var i = 0; i < shuffledWord.length; i++){
this.attachMovie(shuffledWord.charAt(i) + "_letterSY","letter_" + i, this.getNextHighestDepth());
scrambledLetter = this["letter_"+i];
scrambledLetter.onPress = function():Void {
startDrag(this);
correct_mc._visible = false;
}
scrambledLetter.onRelease = function():Void {
stopDrag();
}
}
}
if (shuffledWord.charAt(i) == WordCorrectOrder.charAt(i)) {
a = shuffledWord.charAt(i);
b = wordCorrectOrder.charAt(i);
trace(a);
trace(b);
if (a.hitTest(b)) {
trace("It hit a target");
// This doesn't work because a & b are strings. How do I target the clips that hold a & b?
}
}
placeLines();
placeTargetClips ();
placeScrambledLetters ();
function rand() {
return random(3)-1;
}
words_arr = new Array('POND', 'BUGS', 'ANIMALS', 'PLANTS', 'SWAMP', 'INSECTS', 'FROGS', 'ANTS', 'MOSQUITOS');
randomIncr = Math.floor(Math.random() * words_arr.length);
randomWord = String(words_arr[randomIncr]);
wordCorrectOrder = randomWord.split("").join("");
shuffledWord=randomWord.split("").sort(rand).join("");
function placeLines () {
for(var i = 0; i < shuffledWord.length; i++){
this.attachMovie("mcTargetSymbol", "line_mc" + i, this.getNextHighestDepth());
targetLine = this["line_mc"+i];
}
}
function placeTargetClips () {
for(var i = 0; i < shuffledWord.length; i++){
this.attachMovie("targetLetterSY","targetWord_" + i, this.getNextHighestDepth());
targetLetterClip = this["targetWord_" + i];
targetLetterClip.target_letter.text = wordCorrectOrder.charAt(i);
}
}
function placeScrambledLetters () {
for(var i = 0; i < shuffledWord.length; i++){
this.attachMovie(shuffledWord.charAt(i) + "_letterSY","letter_" + i, this.getNextHighestDepth());
scrambledLetter = this["letter_"+i];
scrambledLetter.onPress = function():Void {
startDrag(this);
correct_mc._visible = false;
}
scrambledLetter.onRelease = function():Void {
stopDrag();
}
}
}
if (shuffledWord.charAt(i) == WordCorrectOrder.charAt(i)) {
a = shuffledWord.charAt(i);
b = wordCorrectOrder.charAt(i);
trace(a);
trace(b);
if (a.hitTest(b)) {
trace("It hit a target");
// This doesn't work because a & b are strings. How do I target the clips that hold a & b?
}
}
placeLines();
placeTargetClips ();
placeScrambledLetters ();