1 Reply Latest reply on Jun 13, 2006 10:15 AM by Newsgroup_User

    Random and Arrays problem

    sbryner Level 1
      Hello,

      I'm trying to select a random number between 1 and 3. Add text in front to create my array name...
      (example: myArray3).

      The code below is what I've come up with. Am I way out in left field or am I somewhat close?
      not sure if var Arrays should be in a function or not?

      Please review code and help me dicipher what I'm doing wrong. I'm just trying to practice new things and understand all this AS stuff.

      I believe I'm not getting the random number into my function. So randRange = null. would I put randRange()
      and in my function (myStoryArray[randRange()]);

      Thanks for any help,

      Sky
        • 1. Re: Random and Arrays problem
          Level 7
          var storyName = myStoryArray[randRange(1,3)];


          --
          Lon Hosford
          www.lonhosford.com
          Flash, Actionscript and Flash Media Server examples:
          http://flashexamples.hosfordusa.com
          May many happy bits flow your way!
          "sbryner" <webforumsuser@macromedia.com> wrote in message
          news:e6mqoa$otr$1@forums.macromedia.com...
          > Hello,
          >
          > I'm trying to select a random number between 1 and 3. Add text in front to
          > create my array name...
          > (example: myArray3).
          >
          > The code below is what I've come up with. Am I way out in left field or am
          > I
          > somewhat close?
          > not sure if var Arrays should be in a function or not?
          >
          > Please review code and help me dicipher what I'm doing wrong. I'm just
          > trying
          > to practice new things and understand all this AS stuff.
          >
          > I believe I'm not getting the random number into my function. So randRange
          > =
          > null. would I put randRange()
          > and in my function (myStoryArray[randRange()]);
          >
          > Thanks for any help,
          >
          > Sky
          >
          > //....................................... Select a random number between 1
          > &
          > 3...................................................\\
          >
          > function randRange(min:Number, max:Number):Number {
          > var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
          > return randomNum;
          > }
          > for (var i = 0; i++; ) {
          > var n:Number = randRange(1, 3);
          > }
          >
          >
          > //........................................................................Functi
          > on....................................................\\
          >
          > myBtn_mc.onRelease = function() {
          > randRange; // calls the random function and retrieves a random
          > number 1
          > - 3
          >
          > var myStoryArray:Array = new Array(); //creates new array called
          > myStoryArray
          > myStoryArray[1] = "My, oh my "+(vFirst)+" "+(vLast)+" array # 1 is
          > here!";
          > myStoryArray[2] = "Well, "+(vFirst)+" "+(vLast)+" Array # 2 works.";
          > myStoryArray[3] = "Hello "+(vFirst)+" "+(vLast)+" This is array # 3.";
          > //lists 3 myStoryArrays
          >
          > var vFirst = fName_txt.text; // sets vFirst = to text in a field
          > var vLast = lName_txt.text; // sets vLast = to text in a field
          > fName_txt._visible = false; // turns visible off of input field
          > lName_txt._visible = false; // turns visible off of input field
          >
          > var storyName = (myStoryArray[randRange]); // sets storyName to
          > myStoryArray[]
          > // (exmpl: myStoryArray3)
          >
          > storyBox_txt.text = storyName; // puts text of array variable
          > name(myStoryArray
          )
          > // into the text of storyBox_txt.
          >
          > };
          >