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 SkipVought 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
0
0
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
 
both of them it comes back with - undefined: undefined

Peter
CCNA, Cisco Qualified Specialist
 
The fact that [tt]correctMCList[/tt] is [tt]undefined[/tt] means [tt]i[/tt] is over the index range of [tt]correctMCList[/tt]. How many items in [tt]correctMCList[/tt]? Are you trying to get more items than that?

Kenneth Kawamoto
 
there are only 10 items in the array at the moment and i was trying to access 3 of them

Peter
CCNA, Cisco Qualified Specialist
 
yea, I have prob done something wrong somewhere just can't figure it out.

Code:
stop();
correct._visible = false;
wrong._visible = false;
frog.stop();
bin.stop();
nextButton._visible = false;

var croakSound = new Sound();
croakSound.attachSound("croak");


var correctArray:Array = ["bandMC", "bendMC", "brandMC", "endMC", "grandMC", "handMC", "mendMC", "sandMC", "sendMC", "standMC"];

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);


var correctCount:Number = 3;

var m:Number = correctCount;
var correctMCList:Array = new Array(m);
while (m) {
	--m;
	correctMCList[m] = correctArray[m];
}
trace("correctMCList: " + correctMCList);

startButton.onRelease = function() {
	startButton._visible = false;
	nextButton._visible = true;
	instructions._visible = false;
	for (var i:Number = 0; i<correctCount; i++) {
		_root.attachMovie(correctMCList[i], correctMCList[i], _root.getNextHighestDepth(),{_x:100+200*i, _y:100+200*i});
	}
};
nextButton.onRelease = function() {
	gotoAndStop(2);
};
trace(correctMCList[i] + ": " + _root[correctMCList[i]]);

Peter
CCNA, Cisco Qualified Specialist
 
Oh yea! oops I put it there is no longer prints them on to the screen. The output comes back with the 3 movieclips but says that each movieclip is undifined

Peter
CCNA, Cisco Qualified Specialist
 
Do you mean you get [tt]bandMC: undefined[/tt]? If so you do not have the MovieClip linkage id "bandMC" in the Libaray. Please note this is not the "name" of the MovieClip but the linkage ID.

Kenneth Kawamoto
 
Yes it was coming up as bandMC: undefined. The linkage ID that I have for this particular movieclip is the same "bandMC"

Peter
CCNA, Cisco Qualified Specialist
 
I did a quick test and works just fine.

I have 10 MovieClips in the Library. Linkage IDs are set to "bandMC", "bendMC", "brandMC", "endMC", "grandMC", "handMC", "mendMC", "sandMC", "sendMC", and "standMC". I also have another MovieClip in the Library which acts as a button. Place the button MovieClip on Stage, name as "startButton". Nothing else on Stage.
Code:
// same as yours basically
var correctArray:Array = ["bandMC", "bendMC", "brandMC", "endMC", "grandMC", "handMC", "mendMC", "sandMC", "sendMC", "standMC"];

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;
}

var correctCount:Number = 3;

var m:Number = correctCount;
var correctMCList:Array = new Array(m);
while (m) {
	--m;
	correctMCList[m] = correctArray[m];
}

startButton.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});
		trace(correctMCList[i]+": "+_root[correctMCList[i]]);
	}
};
Clicking on the button produces 3 MovieClips on Stage. I also get the Output as:
Code:
sandMC: _level0.sandMC
standMC: _level0.standMC
grandMC: _level0.grandMC

Kenneth Kawamoto
 
Mine seems to be working too now, not sure what was wrong. To change the position of the movieclips on the screen do I just change the paramaters at the end of the attatchmovie statement?

Peter
CCNA, Cisco Qualified Specialist
 
Is there a way to set the position of each movieclip separately I have tried a number of different ways but can't seem to do it?

Peter
CCNA, Cisco Qualified Specialist
 
I wanted to have them sort of scattered on the stage

Peter
CCNA, Cisco Qualified Specialist
 
You can either mathematically scatter around them (with or without [tt]Math.random()[/tt]), or predefine the positions in an Array. Either way, you should do it within [tt]attachMovie()[/tt]

Kenneth Kawamoto
 
Cool thanks, so if I make an array with the positions that I want to put them in how would I insert this within the attatchMovie()?

Thanks for the help


Peter
CCNA, Cisco Qualified Specialist
 
Say if you set up an array like this:
[tt]var locs:Array = [{_x:112, _y:343}, {_x:604, _y:701}, {_x:434, _y:90}];[/tt]
You can do like:
[tt]_root.attachMovie(correctMCList, correctMCList, _root.getNextHighestDepth(), locs);[/tt]

Kenneth Kawamoto
 
I have made an array with the positions that I want them in and I have added the array to the end of the attatch movie statement but the movieclips appear in the top left hand corner on top of each other

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

Part and Inventory Search

Sponsor

Back
Top