johnkainn
05-19-2005, 12:15 PM
Hello,
I am creating a math sheet. I found following code in your forum. The code works very well, but I’m having a problem displaying it in a certain way in the stylesheet.
I would like the text to be displayed in two lines in a textfield. Before a “+” symbol a new line would start.
Example: “23+5” would therefore go into two lines, i.e.
1. line) 23 2. line) +5 ?
23
+5
I just recently started learning Actionscript and I would appreciate if someone can help me with this.
//how many sums do we want to end up with?
var numSums:Number = 13;
//create arrays:
var array1:Array = new Array();
var array2:Array = new Array();
var array3:Array = new Array();
var array4:Array = new Array();
//populate arrays:
array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
array2 = [2, 5, 10];
//use one loop inside another to create a third array:
for (i=0; i<array1.length; i++) {
for (j=0; j<array2.length; j++) {
array3.push(array1[i]+" + "+array2[j]+" = ");
}
}
//run a trace to check the contents of array3:
trace("there are "+array3.length+" sums in the new array:");
for (sum in array3) {
trace(array3[sum]);
}
//pick sums out at random:
for (i=0; i<numSums; i++) {
//get a random number. Use Math.floor because arrays always count from zero:
var dice:Number = Math.floor(Math.random()*array3.length);
trace("dice = "+dice);
//put this sum into the fourth array:
array4.push(array3[dice]);
//cut this sum out of array3 so it's not picked again:
array3.splice(dice, 1);
}
//your final result:
trace("******* resulting array *********");
for (sum in array4) {
trace(array4[sum]);
}
//I added this code to display the text fields. The textfield is within a movieClip called example and I call it e1.text.
var xSpacing:Number = 80;
var ySpacing:Number = 80;
var xStart:Number = 190;
var yStart:Number = 30;
var v:Number = 0;
var i:Number = -1;
var spacing = 60;
while (++i<3) {
var j:Number = -1;
while (++j<4) {
++v;
var name:String = "example"+v+"_mc";
_root.attachMovie("example", name, v);
_root[name]._y = y;
_root[name]._x = xStart+i*xSpacing;
_root[name]._y = yStart+j*ySpacing;
_root[name].e1.text = array4[v];
}
}
I am creating a math sheet. I found following code in your forum. The code works very well, but I’m having a problem displaying it in a certain way in the stylesheet.
I would like the text to be displayed in two lines in a textfield. Before a “+” symbol a new line would start.
Example: “23+5” would therefore go into two lines, i.e.
1. line) 23 2. line) +5 ?
23
+5
I just recently started learning Actionscript and I would appreciate if someone can help me with this.
//how many sums do we want to end up with?
var numSums:Number = 13;
//create arrays:
var array1:Array = new Array();
var array2:Array = new Array();
var array3:Array = new Array();
var array4:Array = new Array();
//populate arrays:
array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
array2 = [2, 5, 10];
//use one loop inside another to create a third array:
for (i=0; i<array1.length; i++) {
for (j=0; j<array2.length; j++) {
array3.push(array1[i]+" + "+array2[j]+" = ");
}
}
//run a trace to check the contents of array3:
trace("there are "+array3.length+" sums in the new array:");
for (sum in array3) {
trace(array3[sum]);
}
//pick sums out at random:
for (i=0; i<numSums; i++) {
//get a random number. Use Math.floor because arrays always count from zero:
var dice:Number = Math.floor(Math.random()*array3.length);
trace("dice = "+dice);
//put this sum into the fourth array:
array4.push(array3[dice]);
//cut this sum out of array3 so it's not picked again:
array3.splice(dice, 1);
}
//your final result:
trace("******* resulting array *********");
for (sum in array4) {
trace(array4[sum]);
}
//I added this code to display the text fields. The textfield is within a movieClip called example and I call it e1.text.
var xSpacing:Number = 80;
var ySpacing:Number = 80;
var xStart:Number = 190;
var yStart:Number = 30;
var v:Number = 0;
var i:Number = -1;
var spacing = 60;
while (++i<3) {
var j:Number = -1;
while (++j<4) {
++v;
var name:String = "example"+v+"_mc";
_root.attachMovie("example", name, v);
_root[name]._y = y;
_root[name]._x = xStart+i*xSpacing;
_root[name]._y = yStart+j*ySpacing;
_root[name].e1.text = array4[v];
}
}