Hello,
I’m new to AS3 and am trying to figure out what to do here. I made a class for a button, it seems to work alright. I was having trouble passing a variable through a function with an event listener, but after looking around I think I figured that part out:
package{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class button extends Sprite{
public var container:Sprite = new Sprite();
public function button(anchor, bmapdata, bmdx, bmdy, bx, by, num):void {
var graphic:Bitmap = new Bitmap(new bmapdata(bmdx,bmdy));
container.addEventListener(MouseEvent.CLICK, buttonClick);
container.addChild(graphic);
anchor.addChild(container);
container.x = bx;
container.y = by;
container.name = num;
}
private function buttonClick(evt:MouseEvent):void {
var vari:int;
vari = int(container.name);
vari = vari+1;
trace(container.name);
container.name = vari.toString();
}
}
}
Now my problem is when I make the main class, the variable doesn’t show up in my text box:
package{
import flash.display.Sprite;
import flash.text.TextField;
import button;
public class main extends Sprite{
public var gamearea:Sprite = new Sprite();
public static var num:int = 50;
public function main():void {
this.addChild(gamearea);
var dirpadr:button = new button(gamearea, dirpadright, 55, 52, 0, 0, num);
var txt:TextField = new TextField();
txt.text = dirpadr.container.name;
txt.x = 0;
txt.y = 100;
stage.addChild(txt);
}
}
}
It’s not giving me errors and it traces fine from the button, so I assume the variable just isn’t updating. This isn’t a project or anything, I’m just trying to learn the language.
Any help would be apreciated.