Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating random words using movie clips?

Status
Not open for further replies.

pmoorey

Technical User
Mar 19, 2007
144
GB
Hi

I have been making a memory game, where words are shown to the user. Once they have memorised the words they go to the next screen where the words that they have memorised are shown. They then have to drag each word into a "correct" place and a "wrong" place. I now want to edit it so that I can use two arrays one for correct words and one for wrong words. I want to generate random words from each of these arrays. I have sort of worked out how this is possible to do but using dynamic text, but am I correct in thinking that the whole dragging the words thing is not possible with dynamic text. (I may be wrong though, I am quite new to flash). Are you able to do this with movie clips, or can anyone advise me on how it would be possible to do this?

Thanks


Peter
CCNA, Cisco Qualified Specialist
 
I am also trying to have just the words on the first frame from the correct array then when the button is pressed for the second frame words from the wrong array appear but this doesn't seem to be working.

Thanks

Peter
CCNA, Cisco Qualified Specialist
 
Yea thats right. Sorry I havn't been too clear lol. I will try to explain a little better.

On the first frame I want to display a number of the word movieclips from the "correct" array. Then on the second frame I wish to display those movieclips that have been produced by the button press on the first frame as well as some new movieclips from the "wrong" array.

I had already made the game with movieclips where the player has to look at the words then go to the next frame where words they have not seen are introduced. Then they decide whether or not they have seen them by dragging them to a particular part of the screen. If they are correct or wrong the movieclip is set to be invisible so that the player can not play that same word again.

This worked well its just it would get very repetative having the same words all the time. This is why I have introduced the arrays. So really I just want the game to do the same thing but have a number of different words that can be played.

I hope I have explained it a little better. Thanks again for all your help I really appreciate it :)

Peter
CCNA, Cisco Qualified Specialist
 
Yup thats right

Peter
CCNA, Cisco Qualified Specialist
 
This is the code that I have for the button to show the first movieclips.

Code:
var correctArray:Array = ["bandMC", "bendMC", "brandMC", "endMC", "grandMC", "handMC", "mendMC", "sandMC", "sendMC", "standMC"];
var wrongArray:Array = ["lampMC", "lunchMC", "pinchMC", "straightMC", "tentMC", "wentMC"];
myButton.onRelease = function() {
	_root.attachMovie(correctArray[random(10)], "movieArray", _root.getNextHighestDepth(), {_x:100, _y:100});
	_root.attachMovie(correctArray[random(10)], "movieArray", _root.getNextHighestDepth(), {_x:300, _y:300});
};

its not complete as I am just trying to figure out how to do it before doing it all.

Peter
CCNA, Cisco Qualified Specialist
 
Problems:
[ul]
[li]You could (and will at some point) end up with two identical MovieClips.[/li]
[li]You are naming both the same name so you cannot identify/reference them[/li]
[/ul]


Kenneth Kawamoto
 
Are you refering to the "movieArray" part? Do you think there would be a better way to do this?

Peter
CCNA, Cisco Qualified Specialist
 
The first [tt]correctArray[random(10)][/tt] picks one MC from the Array, and the second [tt]correctArray[random(10)][/tt] picks up another MC, but the second MC can be the same as the first one. Not good.

I would first randomise the Array, then pick the first and second item from it.

To randomise the Array, I use Fisher-Yates algorithm:
Then you have to name the MCs properly so that you can reference them later.

Something like:
Code:
// Not tested ;)
var correctArray:Array = ["bandMC", "bendMC", "brandMC", "endMC", "grandMC", "handMC", "mendMC", "sandMC", "sendMC", "standMC"];
		
// shuffle array
var n:Number = correctArray.length;
while(n){
   var k:Number = Math.floor(Math.random()*n);
   --n;
   var tmp:Object = correctArray[n];
   correctArray[n] = correctArray[k];
   correctArray[k] = tmp;
}
trace("correctArray: " + correctArray);
		
// how many to pick?
var correctCount:Number = 2;
		
// correct MC on Stage list
var m:Number = correctCount;
var correctMCList:Array = new Array(m);
while(m){
   --m;
   correctMCList[m] = correctArray[m];
}
trace("correctMCList: " + correctMCList);
		
// place correct MCs on Stage on button release
myButton.onRelease = function():void {
   for(var i:Number = 0; i < correctCount; i++){
      _root.attachMovie(correctMCList[i], correctMCList[i], _root.getNextHighestDepth(), {_x:100 + 200*i, _y:100 + 200*i});
   }
}

Kenneth Kawamoto
 
Do you know how I can sort out the problem that once the player has placed the movieclip in to their chosen place that it does not disappear. I used ._visible but it says that my movieclip is undefined when I trace it, I am not sure how to fix this?

Thanks



Peter
CCNA, Cisco Qualified Specialist
 
Sorry make a simple naming mistake just took me a while to notice it, sorted now :D

Peter
CCNA, Cisco Qualified Specialist
 
When I press the button to obtain the movie clips sometimes it appears with one too few do you know what the problem could be with this?

thanks

Peter
CCNA, Cisco Qualified Specialist
 
I traced the correct array and all the movie clips seem to be there.

To change the position of the movie clips do I just alter...

Code:
_root.attachMovie(correctMCList[i], correctMCList[i], _root.getNextHighestDepth(), {_x:100+200*i, _y:100+200*i});

thanks for all your help

Peter
CCNA, Cisco Qualified Specialist
 
I traced the correct array and it outputs the number of movieclips that I request, although sometimes one of the movieclips does not actually appear on screen.

Peter
CCNA, Cisco Qualified Specialist
 
It comes back as undefined

Peter
CCNA, Cisco Qualified Specialist
 
no probs, again it came back undefined

Peter
CCNA, Cisco Qualified Specialist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top