3 Replies Latest reply on Apr 23, 2006 3:38 AM by Peter Lorent

    AS Random letter script not working

    DPSwebmaster Level 1
      I have the Flash AS Bible and one of the exercises is to create a random letter displayer. I am not getting any errors in my AS code, so I believe I have that o.k, but when I test movie I only get a blank screen. One part I am unsure about is "using the text tool, add an authoring time dynamic TextField object offstage on the embedded font layer.

      I see ta dynamic text box created, but I am not sure about the rest. I also have it in the embedded font layer.

      Also this part. "Open the Character Embedding dialog box and choose the "specify ranges" option and the value abcdef in the "include these characters" field.

      I see the character embedding dialog box, but not the option to choose "specify ranges". I do see the "include these characters" field.

      Someone please explain what I may be doing wrong.

      Also just FYI herre is the AS code:

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

      //Define an associative array to store data about ecach letter.
      var oLetters bject = new Object();

      function displayLetter():Void {

      //Create a random integer to yield one of the indices from the
      //aLetters array.
      var nRandomIndex:Number = Math.floor(Math.random() *aLetters.length);

      //Create random numbers to use for x and y coordinates of
      // the letter TextField.
      var nRandomX:Number = Math.random() *550;
      var randomY: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
      var tLetter:TextField = this.createTextField("tletter" + nDepth,
      nDepth, nRandomX, nRandomY, 0, 0);

      //Set the autosize and text properties so the random letter displays
      tLetter.autosize = "left";
      //Set the text.
      tLetter.text = aLetters[nRandomIndex];

      //Initialize the _alpha property to 0.

      //Tell Flash to embed the font for the TextField.
      tLetter.embedFonts = true;

      //Define a new object into which to store some data for the letter.
      var oLetter bject = new Object();

      //Assign the object to the oLetters assocaitive array usimg the instance name
      //of the TextField object as the key
      oLetters[tLetter._name] = oLetter;

      //Set a element called fadeDirection that determines
      //the increment by which the alpha will change. And set the
      //alpha to 0 initially.
      oLetter.fadeDirection = 5;

      //Define an element that references the TextField.
      oLetter.letterField = tLetter;

      //Create a TextFormat object that tells Flash to use the
      //Verdana font and sets the size to 15.
      var tfFormatter:TextFormat = new TextFormat();
      tfFormatter.size= 15;

      //Assign the TextFormat to the TextField.

      //Set an interval at which the letter will fade in and out. Assign the ID
      //to a property of the oLetter onject so we can clear it later. Pass the
      //alphaFade() function a reference to the oletter object.
      oLetter.interval = setInterval(alphaFade, 10, oLetter);

      function alphaFade(oLetter bject):Void {

      //Retrieve the TextField object reference.
      var tLetter:TextField = oLetter.letterField;

      //Increment the letter TextField's alpha.
      tLetter._alpha += oLetter.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 clear the interval and remove the TextField.
      if(oLetter.fadeDirection > 0 && tLetter._alpha >=100) {
      oLetter.fadeDirection = -5;
      else if(oLetter.fadeDirection < 0 && tLetter._alpha <=0) {
      delete oLetters[tLetter._name];

      //make sure to update the screen.