Skip to main content
Participating Frequently
February 4, 2013
Question

Making a Dynamic txtfield into array

  • February 4, 2013
  • 1 reply
  • 684 views

Hi guys, im fresh on the forum so sorry if Im breaking any rules.

Anyhow, i have a question regarding arrays. What i want to do, is that i have a dynamic text field in which users can input text, and i wish that this text is splitted into letters, and then add each letter into a array-table of it own.

So far, i've only come to thinking about how to get the whole word into an array,  but it doesent seem to work. This is the code that i've been trying to use:

(guessword is the array, sporsmol.text is the dynamic textbox in which the user enters the word he / or she wishes.)

ActionScript Code:

var guessword:Array = new Array(); guessword[0] = sporsmol.text;

When i use this, i get the following error;

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at skoleprosjekt_fla::MainTimeline/click()

So - I was wondering if anyone could help me out and sort out the code for making the array take the word from the dynamic textbox, and adding it to the array after splitting the word in to letters.

So, for an instance, if the word "cheese" is entered, i should have an array with "colums" "C,H,E,E,S,E".

In advance i would like to say thank you for all the help.

- Scott.

This topic has been closed for replies.

1 reply

February 4, 2013

You can do what you want using the String.split method.

var guessword:Array = String(sporsmol.text).split("");

Participating Frequently
February 4, 2013

Thank you Dmen for the quick answer,

i tried your code but i still get the same error. Im trying to execute this under a "click" command, the whole code for the button is lined below.


Can you see why it won't run? Have i done anything wrong?

start.addEventListener(MouseEvent.MOUSE_DOWN, click);

function click (evt:MouseEvent)

{

gotoAndStop(14);

var guessword:Array = String(sporsmol.text).split("");

}

February 4, 2013

I don't know where you're trying to get at guessword but the way you show it, guessword is local to the click function, so won't be accessible outside of it. Declare it outside the function in order to access it elsewhere.