-
[RESOLVED] Code Output Assistance
Hi there,
for the last couple of nights i've been searching for a tutorial of sorts which might point me in the right direction to coding/developing a sports fixture generator.
fortunately I stumbled across this AS2 code (http://www.kirupa.com/forum/showthre...light=fixtures)
Code:
var teamArr:Array = new Array("New York Jets", "Washington Redskins", "New York Yankees", "Dallas Cowboys", "LA Raiders");
function createFixtures(teamArr:Array, shuffle:Boolean) {
if (shuffle) {
teamArr.sort(function () {
return Math.round(Math.random());
});
}
var teams:Number = teamArr.length;
if (teams & 1 != 0) {
teams++;
teamArr.push("Bye");
}
var totalRounds:Number = teams - 1;
var matchesPerRound:Number = teams / 2;
var fixtureArr:Array = new Array(totalRounds);
for (var round:Number = 0; round < totalRounds; round++) {
fixtureArr[round] = new Array(matchesPerRound);
for (var match:Number = 0; match < matchesPerRound; match++) {
var home:String = teamArr[(round + match) % (teams - 1)];
var away:String = teamArr[(teams - 1 - match + round) % (teams - 1)];
if (match == 0) {
away = teamArr[teams - 1];
}
fixtureArr[round][match] = home + " v " + away;
}
}
var tempArr:Array = new Array(totalRounds);
for (var round:Number = 0; round < totalRounds; round++) {
tempArr[round] = new Array(matchesPerRound);
}
var even:Number = 0;
var odd:Number = (teams / 2);
for (var i:Number = 0; i < fixtureArr.length; i++) {
if (i % 2 == 0) {
tempArr[i] = fixtureArr[even++];
} else {
tempArr[i] = fixtureArr[odd++];
}
}
fixtureArr = tempArr;
for (var round:Number = 0; round < fixtureArr.length; round++) {
if (round % 2 == 1) {
fixtureArr[round][0] = swap(fixtureArr[round][0]);
}
}
// second half of season - comment out if not required
var rounds = fixtureArr.length;
for (var i:Number = rounds; i < rounds * 2; i++) {
fixtureArr[i] = new Array(matchesPerRound);
for (var match:Number = 0; match < matchesPerRound; match++) {
fixtureArr[i][match] = swap(tempArr[i - rounds][match]);
}
}
//
function swap(arg) {
var components:Array = arg.split(" v ");
return components[1] + " v " + components[0];
}
// send fixture list to Output Panel
var fixtureList:String = "";
for (var i:Number = 0; i < fixtureArr.length; i++) {
fixtureList = "Round " + (i + 1) + newline;
for (var match:Number = 0; match < matchesPerRound; match++) {
fixtureList += fixtureArr[i][match];
fixtureList += newline;
}
trace(fixtureList);
}
//return fixtureList;
}
createFixtures(teamArr, true);
now its maybe because its been a long time since I've done anything with Flash properly but I pasted this code into a new FLA file, which I then published but there is no output??
so I was wondering if someone would be kind enough to inform me (by going of the code) how I might get the output of fixtures that I require??
many thanks in advance!!!!
-
.
Hi,
Ok, it does output, but it is traced, so you will not see it in the created swf file.
If you make a multiline text field, selectable ( so you can scroll it), and embed the font (any font), give the text field a name of"myText" and swap your code for this, or add the line i have added, it is commented
PHP Code:
var teamArr:Array = new Array("New York Jets", "Washington Redskins", "New York Yankees", "Dallas Cowboys", "LA Raiders");
function createFixtures(teamArr:Array, shuffle:Boolean)
{
if (shuffle)
{
teamArr.sort(function ()
{
return Math.round(Math.random());
});
}
var teams:Number = teamArr.length;
if (teams & 1 != 0)
{
teams++;
teamArr.push("Bye");
}
var totalRounds:Number = teams - 1;
var matchesPerRound:Number = teams / 2;
var fixtureArr:Array = new Array(totalRounds);
for (var round:Number = 0; round < totalRounds; round++)
{
fixtureArr[round] = new Array(matchesPerRound);
for (var match:Number = 0; match < matchesPerRound; match++)
{
var home:String = teamArr[(round + match) % (teams - 1)];
var away:String = teamArr[(teams - 1 - match + round) % (teams - 1)];
if (match == 0)
{
away = teamArr[teams - 1];
}
fixtureArr[round][match] = home + " v " + away;
}
}
var tempArr:Array = new Array(totalRounds);
for (var round:Number = 0; round < totalRounds; round++)
{
tempArr[round] = new Array(matchesPerRound);
}
var even:Number = 0;
var odd:Number = (teams / 2);
for (var i:Number = 0; i < fixtureArr.length; i++)
{
if (i % 2 == 0)
{
tempArr[i] = fixtureArr[even++];
}
else
{
tempArr[i] = fixtureArr[odd++];
}
}
fixtureArr = tempArr;
for (var round:Number = 0; round < fixtureArr.length; round++)
{
if (round % 2 == 1)
{
fixtureArr[round][0] = swap(fixtureArr[round][0]);
}
}
// second half of season - comment out if not required
var rounds = fixtureArr.length;
for (var i:Number = rounds; i < rounds * 2; i++)
{
fixtureArr[i] = new Array(matchesPerRound);
for (var match:Number = 0; match < matchesPerRound; match++)
{
fixtureArr[i][match] = swap(tempArr[i - rounds][match]);
}
}
//
function swap(arg)
{
var components:Array = arg.split(" v ");
return components[1] + " v " + components[0];
}
// send fixture list to Output Panel
var fixtureList:String = "";
for (var i:Number = 0; i < fixtureArr.length; i++)
{
fixtureList = "Round " + (i + 1) + newline;
for (var match:Number = 0; match < matchesPerRound; match++)
{
fixtureList += fixtureArr[i][match];
fixtureList += newline;
}
trace(fixtureList);
myText.text += fixtureList + "\n";// ADDDED THIS LINE HERE
}
//return fixtureList;
}
createFixtures(teamArr,true);
-
Thanks very much! Greatly appreciated!!
Originally Posted by fruitbeard
Hi,
Ok, it does output, but it is traced, so you will not see it in the created swf file.
If you make a multiline text field, selectable ( so you can scroll it), and embed the font (any font), give the text field a name of"myText" and swap your code for this, or add the line i have added, it is commented
PHP Code:
var teamArr:Array = new Array("New York Jets", "Washington Redskins", "New York Yankees", "Dallas Cowboys", "LA Raiders");
function createFixtures(teamArr:Array, shuffle:Boolean)
{
if (shuffle)
{
teamArr.sort(function ()
{
return Math.round(Math.random());
});
}
var teams:Number = teamArr.length;
if (teams & 1 != 0)
{
teams++;
teamArr.push("Bye");
}
var totalRounds:Number = teams - 1;
var matchesPerRound:Number = teams / 2;
var fixtureArr:Array = new Array(totalRounds);
for (var round:Number = 0; round < totalRounds; round++)
{
fixtureArr[round] = new Array(matchesPerRound);
for (var match:Number = 0; match < matchesPerRound; match++)
{
var home:String = teamArr[(round + match) % (teams - 1)];
var away:String = teamArr[(teams - 1 - match + round) % (teams - 1)];
if (match == 0)
{
away = teamArr[teams - 1];
}
fixtureArr[round][match] = home + " v " + away;
}
}
var tempArr:Array = new Array(totalRounds);
for (var round:Number = 0; round < totalRounds; round++)
{
tempArr[round] = new Array(matchesPerRound);
}
var even:Number = 0;
var odd:Number = (teams / 2);
for (var i:Number = 0; i < fixtureArr.length; i++)
{
if (i % 2 == 0)
{
tempArr[i] = fixtureArr[even++];
}
else
{
tempArr[i] = fixtureArr[odd++];
}
}
fixtureArr = tempArr;
for (var round:Number = 0; round < fixtureArr.length; round++)
{
if (round % 2 == 1)
{
fixtureArr[round][0] = swap(fixtureArr[round][0]);
}
}
// second half of season - comment out if not required
var rounds = fixtureArr.length;
for (var i:Number = rounds; i < rounds * 2; i++)
{
fixtureArr[i] = new Array(matchesPerRound);
for (var match:Number = 0; match < matchesPerRound; match++)
{
fixtureArr[i][match] = swap(tempArr[i - rounds][match]);
}
}
//
function swap(arg)
{
var components:Array = arg.split(" v ");
return components[1] + " v " + components[0];
}
// send fixture list to Output Panel
var fixtureList:String = "";
for (var i:Number = 0; i < fixtureArr.length; i++)
{
fixtureList = "Round " + (i + 1) + newline;
for (var match:Number = 0; match < matchesPerRound; match++)
{
fixtureList += fixtureArr[i][match];
fixtureList += newline;
}
trace(fixtureList);
myText.text += fixtureList + "\n";// ADDDED THIS LINE HERE
}
//return fixtureList;
}
createFixtures(teamArr,true);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|