PDA

View Full Version : question about I/O.


Auctane
09-04-2007, 02:15 AM
Hi there, I'm new here. I've just started learning ActionScript 3.0. I have some programming experience. I have a bunch of programs I want to write and I bought some books, Essential ActionScript 3 being the one I'm part way through now. The thing is, none of the books i bought really touch on basic programs. So I took it upon myself to start experimenting with code. I've done a couple small programs now, but this one stopped me and I've been searching all over the internet for tutorials or example code and cannot find any.

Heres what I want to do:

Wise Guy -
1) I have a DynamicText box that greets the user and asks their name
2) There is a TextInput field for them to enter their name.
3) Generate a random boolean for a var 'wiseGuy'
4) In the DynamicText box, the text changes to "Hello (name entered by user), you are (or are not) a wise guy."

right now my code looks like this and doesn't work:

var hi;
var player;
var wiseGuy;
wiseGuy = Math.random();

player = playerName_txt;

if (wiseGuy >= .5){
hi = (player + ", you are a WISE GUY!!");
}else{
hi = (player + ", you are not a wise guy.");
}
hello_txt = hi;

~edit: I changed the code and cut back to ActionScript 2 so I could tie a var to the text field. Now my only problem is to get the input text to wait for text and then continue into the coin flop...

Pointing me at some code or a tutorial or help would be seriously appreciated.

Flash Gordon
09-04-2007, 04:18 AM
player = playerName_txt.text

hello_txt.text = hi;

Auctane
09-04-2007, 02:27 PM
Thanks Flash Gordon. So adding the .text makes it so you can use those the same way in AS3 as you do with the var pram in AS2?

Well I got it working last night, I found someone else that wanted to do the same thing, so I took their code... So I'm kinda bummed on that. But future reference for anyone - heres what I ended up with:
var hi;
var player;
var wiseGuy;
var enterKeyListener;
var player:String = new String();
var enterKeyListener:Object = new Object();

enterKeyListener.onKeyDown = function():Void{
if(Key.isDown(Key.ENTER)){
player = playerName_txt.text;
nameAssign();
}
};
Key.addListener(enterKeyListener);
function nameAssign():Void{
wiseGuy = Math.random(); // >= .5;
if (wiseGuy >= .5){
hi = (player + ", you are a WISE GUY!!");
}else{
hi = (player + ", you are not a wise guy.");
}
hello_txt = hi;
};