Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i tried actionscript recently,am little scared i want to make a game that input a word from about 3000 randomly, do actionscript support that,or should i try another language?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

The question isn't really about ActionScript supporting it, but rather if your output platform supports it. With Flash/ActionScript you can build AIR applications, which can read files (all kinds of files) from the file-system (using the FileStream class).

If want to create a SWF file that runs in a web-browser instead, FileStream won't work. If you want to read local files or files from a different server, you'll face some security/sandboxing issues. The easiest way to load a file in a web-based flash-application is to have the text-file in the same directory as your swf file and then load it using URLLoader (the file and your SWF have to be on a web-server).

So yes, loading such a file and picking words randomly should be easy, as long as you use the correct methods to load it...

share|improve this answer
    
thx,to be specific AS2 in flash mx 2004 and AS3 CS –  md nth Sep 26 '12 at 16:02
    
You can load files from URLs in AS2 (I believe it was called LoadVars). The things I mentioned in my answer (URLLoader or FileStream) are AS3 classes. –  bummzack Sep 26 '12 at 16:04

AS3: Do you want to the change the word collection frequently? You could embed the word collection in the game itself using:

[Embed(source="textFileName.txt")]
private var TextFile:Class;

If it is under 10,000 words, I would create a static literal vector of all the words.

var words:Vector.<String> = new <String>["word", "another word", "third word", "more words", "etc"];

This can be accomplished easily with a Text Editor like notepad++ or running some simple regular expression on the text content of the file. You will likely wanna replace all line breaks ("\n") with a comma (","). This would save you the time of messing with loading assets externally. Which according to my best knowledge is not approved of in some game websites.

share|improve this answer
    
good idea,my first solution was to read them ,because they are ready in text file,i need to edit them before putting them in vector "the coma problem",and that takes time,i prefer reading from file , eg pneomonia "enter" then heartfailure "enter",actually am using the index of a book to give you the big picture –  md nth Sep 26 '12 at 17:25
    
You can still embed the file using: [Embed(source="fileName.txt")] private var Text:Class; (which requires no editing) Editing only takes a 15 seconds in a decent text editor - You should be able to replace all (line breaks) "\n" or "\r" with "," –  Zehelvion Sep 26 '12 at 17:33
    
sorry for being late,its flashcard game what am doing,so i choose one word randomly and show it in screen. –  md nth Sep 26 '12 at 17:42
    
You can do a (int)Math.random() * words.length to get one –  Zehelvion Sep 26 '12 at 18:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.