Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 2 of 2

Hybrid View

  1. #1

    Default From an array to textbox - how do i do this?

    Hi everyone,
    I have built a flash game that generates x number of random numbers then pushes them into an array:

    Code:
    stop();
    //Scripts file for all functions//
    var pickNumber = numberPick;//VARIABLE FROM INPUT BOX//
    // Choose x numbers from a list of y numbers (ranging from 1 - x-1)
    x = 73;
    y = pickNumber;
    myArray = [];
    ///////////////////////////////////////////
    for &#40;i = 1; i < x && y > 0; ++i&#41; &#123;
    	if &#40;random&#40;x-i&#41; < y&#41; &#123;
                myArray.push&#40;i&#41;;
    	   		y--;
    	&#125;
    &#125;
    ///////////////////////////////////////////
    MY questions is how to get the random numbers from the array into a grid style or "keno" style game board?

    My code for the button is

    Code:
    on&#40;press, keyPress "<Enter>"&#41; &#123;
    	drawnNumbers = myArray;//Echo all the elements in the array to a text box//
    	
    	myArray_length = &#40;myArray.length&#41;;//find the length of the array//
    	for&#40;i=0; i < myArray_length; i++&#41; &#123;//loop for each element in the array//
    		trace&#40;myArray&#91;i&#93;&#41;;//trace each element based on the length of the array until i = myArray_length//
    		box&#91;i&#93; = myArray&#91;i&#93;;//assign the value of each element in the appropriate text 
    		                      //box and display it in that text box//
    	&#125;//end of loop//
    	this.play&#40;&#41;;	
    &#125;
    Any ideas on how to do so?

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    I suggested a better way on Flashkit. Instead of generating random numbers and pushing them into an array. Push all of the board numbers into an array. You can then randomly pick one of the numbers in the array for the chosen number. Splicing the chosen number value from the array prevents repeated values. You can programatically create a grid for the spots and numbers but it will require a good understanding of AS. An easier method is to use two frame movieclips for the individual spots(80 total I think). First frame would show the number unchosen. Second frame shows the number chosen. If you use a standard naming convention for the movieclips...spot1 - spot 80... you can simply concatenate the string "spot" to the randomly chosen number from the array to tell the target movieclip to go to the next frame and show that it is chosen.

    Just for kicks, here is what the actionscript would look like for creating a grid programatically with the drawing api...
    Code:
    MovieClip.prototype.makeSquare = function&#40;w, c, a, fc, fa, x, y, width, height&#41; &#123;
    	this.lineStyle&#40;w, c, a&#41;;
    	this.beginFill&#40;fc, fa&#41;;
    	this.moveTo&#40;x, y&#41;;
    	this.lineTo&#40;width, y&#41;;
    	this.lineTo&#40;width, height&#41;;
    	this.lineTo&#40;x, height&#41;;
    	this.lineTo&#40;x, y&#41;;
    	this.endFill&#40;&#41;;
    &#125;
    squareGrid2D = function &#40;startX, startY, Rows, Colls, xOffset, yOffset, mc2PlaceInGridName, w, c, a, fC, fA, SquareWidth, squareHeight&#41; &#123;
    	this.createEmptyMovieClip&#40;"gridHolder", 9999999&#41;;
    	for &#40;var y = 0; y<Colls; y++&#41; &#123;
    		for &#40;var x = 0; x<Rows; x++&#41; &#123;
    			tiles++;
    			this.gridHolder.createEmptyMovieClip&#40;mc2PlaceInGridName+tiles, tiles&#41;;
    			this.gridHolder&#91;mc2PlaceInGridName+tiles&#93;.makeSquare&#40;w, c, a, fC, fA, SquareWidth, squareHeight&#41;;
    			this.gridHolder&#91;mc2PlaceInGridName+tiles&#93;._x = startX+&#40;x*this.gridHolder&#91;mc2PlaceInGridName+tiles&#93;._width&#41;-xOffset;
    			this.gridHolder&#91;mc2PlaceInGridName+tiles&#93;._y = startY+&#40;y*this.gridHolder&#91;mc2PlaceInGridName+tiles&#93;._height&#41;-yOffset;
    		&#125;
    	&#125;
    &#125;
    squareGrid2D&#40;200, 250, 4, 3, 0, 50, "square", 2, 0x00dd00, 100, 0xff0000, 50, 50, 50&#41;;
    If your not heavily invested in AS, it would be easier to create the clips manually.
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Load all of a directory (server-side) into an array?
    By frank in forum Flash Scripting
    Replies: 1
    Last Post: 10-17-2006, 10:23 PM
  2. Array problem
    By Shiroten in forum Flash Scripting
    Replies: 2
    Last Post: 10-10-2006, 03:09 AM
  3. Replies: 0
    Last Post: 05-27-2005, 12:29 AM
  4. xml database and dinamic menu from created array
    By cocas in forum Advanced Flash
    Replies: 0
    Last Post: 10-12-2004, 12:16 AM
  5. Help with viewing items in an array.
    By dchil82 in forum Newbies
    Replies: 0
    Last Post: 12-04-2003, 12:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial