2 Replies Latest reply on Feb 16, 2007 6:55 PM by injpix

    Converting to number

    cuber3
      I'm trying to make a little typing app, which loads the exercises externally from text files.
      Here's what's in my text file:

      ===================
      ex1.text
      ===================

      &words=12
      &word0=jjj
      &word1=jjj
      &word2=jjj
      &word3=jjj
      &word4=jjj
      &word5=jjj
      &word6=jjj
      &word7=jjj
      &word8=jjj
      &word9=jjj
      &word10=jjj
      &word11=jjj

      words being the amount of words in the exercise (12), and the rest being the words which should be typed.

      ===================
      The Flash File (frame 1)
      ===================

      var exerciseArray:Array = new Array();
      var exLoadVars = new LoadVars();
      exLoadVars.onLoad = startExercise;
      exLoadVars.load("ex1.txt");
      function startExercise(success) {
      if (success) {
      // load exercise
      var numberOfWords:Number = Number(exLoadVars.words);
      trace(numberOfWords);
      for (i=0; i<numberOfWords; i++) {
      trace("test");
      }
      } else {
      trace("loading failed");
      }
      }

      This should load my text file, and when I trace exLoadVars.words, it outputs '12' just like it's supposed to.
      However, if I convert this string to a number using var numberOfWords:Number = Number(exLoadVars.words);
      and then trace(numberOfWords); it outputs isNaN.
      (obviously, the trace("test") does not fire at all because numberOfWords is not a number)

      Why doesn't this work ??