00:00
00:00
Newgrounds Background Image Theme

Chan99 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Simple help with AS2 variables!

513 Views | 5 Replies
New Topic Respond to this Topic

Simple help with AS2 variables! 2016-10-24 20:51:01


Hey guys... I am just about finished a new flash game of mine... and I am running into the same problem I ran in to on the last two games I made... but those were 7 and 10 years ago and I cannot remember what I did to fix it!

I just have a simple input text box where I want the user to be able to put in a continue code to jump to a later level in the game

so I have a button like this:

on(press) {
if(_root.codehere == 1337)
_root.gotoAndStop(24)
}

So if I set the variable using code ex 'var codehere = 1337' then it works. BUT if the user types it into the box it doesn't work. I remember pulling my hair out for hours on this simple thing before... Please help!

Response to Simple help with AS2 variables! 2016-10-24 21:17:32


Your _root.codehere variable doesn't contain the value put into the text input because it wasn't assigned that value. You can either assign it the value or simply compare to the value in the text input. You can get the value by using the _text property:

on(press) {
  if (myTextInput._text == 1337)
    _root.gotoAndStop(24)
  }
}

At 10/24/16 09:17 PM, Diki wrote: Your _root.codehere variable doesn't contain the value put into the text input because it wasn't assigned that value. You can either assign it the value or simply compare to the value in the text input. You can get the value by using the _text property:

on(press) {
if (myTextInput._text == 1337)
_root.gotoAndStop(24)
}
}

So the input text box was called codehere, and I could insert values into it using code, and I could see those values in the box. and I would click the button and it would take me to the desired frame, but for some reason when it is typed, as opposed to getting the value from code... it just doesn't work.

I just dont get it. I tried copying your code and renamed the text box to myTextInput and still no luck. If somebody could make an example FLA of this working I would be eternally grateful, as I swear to god I am cursed with this simple function.


So a new example, with this code in the first frame of a fla. codehere is input text and midcode is dynamic text

var codehere = "apple"
var midcode = 0

cheese.onEnterFrame = function() {
midcode = codehere
if(codehere == "apple"){
gotoAndStop(2);
}
}

This brings me to frame 2.
however if I do var codehere = "appl"
and type in e
nothing happens.
Could somebody please tell me what I'm doing wrong. I would greatly appreciate it. Thanks!


At 10/24/16 11:10 PM, iameatingjam wrote: So a new example, with this code in the first frame of a fla. codehere is input text and midcode is dynamic text

var codehere = "apple"
var midcode = 0

cheese.onEnterFrame = function() {
midcode = codehere
if(codehere == "apple"){
gotoAndStop(2);
}
}

This brings me to frame 2.
however if I do var codehere = "appl"
and type in e
nothing happens.
Could somebody please tell me what I'm doing wrong. I would greatly appreciate it. Thanks!

1. You're declaring two variables, "codehere" (string, in frame script) and "codehere" (textfield on stage). Remove the "var codehere = 'apple'" line.

2. In AS2 there's this queer "feature" where in a textfield you have two variable fields. Go to the properties tab of the textField, and scroll down. Under the field "options" (I forget what it's called) there'll be a field called "variable" or something (no, not the thing at the top, it's inside the scrollpane). Set -that- value to "codehere", and remove "codehere" from the instance name of the textfield.

3. If that doesn't work, try "codehere._text" instead.

4. If all else fails, switch to as3 or something.

Edit: Like so:

Simple help with AS2 variables!


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

Response to Simple help with AS2 variables! 2016-11-06 20:23:30


At 10/28/16 02:40 AM, Gimmick wrote:
At 10/24/16 11:10 PM, iameatingjam wrote: So a new example, with this code in the first frame of a fla. codehere is input text and midcode is dynamic text

var codehere = "apple"
var midcode = 0

cheese.onEnterFrame = function() {
midcode = codehere
if(codehere == "apple"){
gotoAndStop(2);
}
}

This brings me to frame 2.
however if I do var codehere = "appl"
and type in e
nothing happens.
Could somebody please tell me what I'm doing wrong. I would greatly appreciate it. Thanks!
1. You're declaring two variables, "codehere" (string, in frame script) and "codehere" (textfield on stage). Remove the "var codehere = 'apple'" line.

2. In AS2 there's this queer "feature" where in a textfield you have two variable fields. Go to the properties tab of the textField, and scroll down. Under the field "options" (I forget what it's called) there'll be a field called "variable" or something (no, not the thing at the top, it's inside the scrollpane). Set -that- value to "codehere", and remove "codehere" from the instance name of the textfield.

3. If that doesn't work, try "codehere._text" instead.

4. If all else fails, switch to as3 or something.

Edit: Like so:

Thanks man! I ended up finding another solution which was to have 10 buttons, one for every digit with code like

on(press) {
	_root.codehere += "3"
		_root.block.play()
}

and then

if(_root.codehere == "061215"){
_root.points = 0
_root.lives = 3
	_root.gotoAndStop(47)
}

kind of a shitty roundabout way but it worked...