macliems
%Europe/Berlin %448 %2005, 11:46
Hieronder het script voor random letters uit Actionscript Bible.
Er worden twee intervallen geset. Het eerste heb ik al aangepast van setInterval(this, "alphaFade", 10, tLetter) tot setInterval(alphaFade, 10, tLetter). Dat ging goed.
Ik zou hetzelfde willen doen met het tweede (helemaal aan het eind). Immers, de daar gebruikte syntax is - dacht ik - voor calls van object methods? En de functie displayLetters() is toch geen object method? Waarom dan deze syntax? Zoals ik het zou doen (dus setInterval(displayLetter, 1)) werkt het niet. Iemand die mij kan uitleggen wat ik hier verkeerd begrijp?
function displayLetter():Void {
// Create a random integer to yield one of the indices from the aLetters array.
var nRandomIndex:Number = Math.ceil(Math.random() * aLetters.length) - 1;
// Create random numbers to use for the x and y coordinates of the letter TextField.
var nRandomX:Number = Math.random() * 550;
var nRandomY:Number = Math.random() * 400;
// Get the next available depth;
var nDepth:Number = this.getNextHighestDepth();
// Create a new TextField object at the random x and y coordinates.
this.createTextField("tLetter" + nDepth, nDepth, nRandomX, nRandomY, 0, 0);
// Assign a reference to a variable to make it more convenient to work with the TextField.
var tLetter:TextField = this["tLetter"+ nDepth];
// Set the autoSize and text properties so the random letter
// displays.
tLetter.autoSize = "left";
tLetter.text = aLetters[nRandomIndex];
// Set a custom property called fadeDirection that determines
// the increment by which the alpha will change. And set the alpha to 0 initially.
tLetter.fadeDirection = 5;
tLetter._alpha = 0;
// Tell Flash to embed the font for the TextField.
tLetter.embedFonts = true;
// Create a TextFormat object that tells Flash to use the Verdana font and set the size to 15.
var tfFormatter:TextFormat = new TextFormat();
tfFormatter.font = "Verdana";
tfFormatter.size = 15;
// Assign the TextFormat to the TextField.
tLetter.setTextFormat(tfFormatter);
// Set an interval at which the letter will fade in and out.
tLetter.nInterval = setInterval(alphaFade, 10, tLetter);
}
function alphaFade(tLetter:TextField):Void {
// Increment the letter TextField’s alpha.
tLetter._alpha += tLetter.fadeDirection;
// Check to see if the letter has faded in completely. If so set the fadeDirection property to -5 so that the TextField
// starts to fade out. Otherwise, if the letter has faded out completely...
if(tLetter.fadeDirection > 0 && tLetter._alpha >= 100) {
tLetter.fadeDirection = -5;
}
else if(tLetter.fadeDirection < 0 && tLetter._alpha <= 0) {
// ... clear the interval and remove the TextField.
clearInterval(tLetter.nInterval);
tLetter.removeTextField();
}
// Make sure to update the screen.
updateAfterEvent();
}
// Create the array of letters.
var aLetters:Array = ["a", "b", "c", "d", "e", "f"];
// Set the interval at which a new letter should be displayed.
var nDisplayInterval:Number = setInterval(this, "displayLetter", 1);
Er worden twee intervallen geset. Het eerste heb ik al aangepast van setInterval(this, "alphaFade", 10, tLetter) tot setInterval(alphaFade, 10, tLetter). Dat ging goed.
Ik zou hetzelfde willen doen met het tweede (helemaal aan het eind). Immers, de daar gebruikte syntax is - dacht ik - voor calls van object methods? En de functie displayLetters() is toch geen object method? Waarom dan deze syntax? Zoals ik het zou doen (dus setInterval(displayLetter, 1)) werkt het niet. Iemand die mij kan uitleggen wat ik hier verkeerd begrijp?
function displayLetter():Void {
// Create a random integer to yield one of the indices from the aLetters array.
var nRandomIndex:Number = Math.ceil(Math.random() * aLetters.length) - 1;
// Create random numbers to use for the x and y coordinates of the letter TextField.
var nRandomX:Number = Math.random() * 550;
var nRandomY:Number = Math.random() * 400;
// Get the next available depth;
var nDepth:Number = this.getNextHighestDepth();
// Create a new TextField object at the random x and y coordinates.
this.createTextField("tLetter" + nDepth, nDepth, nRandomX, nRandomY, 0, 0);
// Assign a reference to a variable to make it more convenient to work with the TextField.
var tLetter:TextField = this["tLetter"+ nDepth];
// Set the autoSize and text properties so the random letter
// displays.
tLetter.autoSize = "left";
tLetter.text = aLetters[nRandomIndex];
// Set a custom property called fadeDirection that determines
// the increment by which the alpha will change. And set the alpha to 0 initially.
tLetter.fadeDirection = 5;
tLetter._alpha = 0;
// Tell Flash to embed the font for the TextField.
tLetter.embedFonts = true;
// Create a TextFormat object that tells Flash to use the Verdana font and set the size to 15.
var tfFormatter:TextFormat = new TextFormat();
tfFormatter.font = "Verdana";
tfFormatter.size = 15;
// Assign the TextFormat to the TextField.
tLetter.setTextFormat(tfFormatter);
// Set an interval at which the letter will fade in and out.
tLetter.nInterval = setInterval(alphaFade, 10, tLetter);
}
function alphaFade(tLetter:TextField):Void {
// Increment the letter TextField’s alpha.
tLetter._alpha += tLetter.fadeDirection;
// Check to see if the letter has faded in completely. If so set the fadeDirection property to -5 so that the TextField
// starts to fade out. Otherwise, if the letter has faded out completely...
if(tLetter.fadeDirection > 0 && tLetter._alpha >= 100) {
tLetter.fadeDirection = -5;
}
else if(tLetter.fadeDirection < 0 && tLetter._alpha <= 0) {
// ... clear the interval and remove the TextField.
clearInterval(tLetter.nInterval);
tLetter.removeTextField();
}
// Make sure to update the screen.
updateAfterEvent();
}
// Create the array of letters.
var aLetters:Array = ["a", "b", "c", "d", "e", "f"];
// Set the interval at which a new letter should be displayed.
var nDisplayInterval:Number = setInterval(this, "displayLetter", 1);