Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Making a Dynamic txtfield into array

New Here ,
Feb 04, 2013 Feb 04, 2013

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.

TOPICS
ActionScript
633
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 04, 2013 Feb 04, 2013

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2013 Feb 04, 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("");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 04, 2013 Feb 04, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2013 Feb 04, 2013

I see. Well, what im eventually doing, is an hangman-sort of game.

I have an UI, with the "sporsmol.text" dynamic text field allocated and a "startbutton"(wich is the button mentioned in the source over.)


The user types in the word of his choice, and then hits "start". The guessword shall then be stored as letters in the array "guessword", and the functioning for the guessing will then start.(Havent coded that yet, but i know how to do it.)

Do you mean that i should declare the array before the button-instance? Is that whats screwing up? Because, i cannot store the array information before the button is clicked.( I mean, there is no reason to store into array before the user has entered his / her word and clicked to start the game)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2013 Feb 04, 2013
LATEST

Oh god, i just found out the problem.
I use "gotoframes" to hide the textbox afterwards, which literally makes Flash think there is an "null" value.


Sorry for my incompetence and thanks for the replies, your code works properly no Dmen.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines