Error 1120: undefined int - simple code
hello!
I am creating a game, and I want to have it so that when a player clicks on a certain button, a particular stat increases (by whatever amount, depending on the button) and it will display that number in a dynamic text box (instance name: stat_text)
Each time I try to do this, though, the stat comes up as being undefined. I tried to fix this but it gives me the same error.
I'm also putting this code right on the timeline
first I just had:
stop();
import flash.events.MouseEvent;
stat_btn.addEventListener(MouseEvent.CLICK, stat_btnClick);
var stat:int=0;
stat_text.text="stat";
function test_btnClick(event:MouseEvent):void {
stat += 1;
}
but it brings up the error:
1120: Access of undefined property stat_text.text="stat";
next i tried to create a constructor for it, telling it that when we enter this frame, the buttonPress event will start and if the button is pressed that stat will be +1, but it still says that stat is undefined.
I'm now guessing that I have to do something like stat = new stat(); but i don't really know why I'd be doing that or what it would be doing. Do I have to create a class for the stats?
(Side note: in some AS3 game tutorials, the codes just call on functions but don't even state them in the beginning -unless it's somewhere on the actual timeline. I feel like I'm missing something...)
Thank you!! I need help