Question
Garbage Collection in AS 2.0 question
I'm a learning AS 2.0 programmer. I'm using a basic event
broadcasting system I found online (I post the internal code at the
end) to handle file loading, button presses, etc. Something like
menuBar_mc.left_btn.onPress = function() {
var evtObj:Object = new Object();
EventBroadcaster.getInstance().broadcastEvent("leftBtnPressed", evtObj);
and I set up the listener
EventBroadcaster.getInstance().addEventListener("leftBtnPressed", this);
which handles it thus
private function leftBtnPressed(evtObj:Object):Void {
var next_pic:Number;
switchPicture(-1);
Do I need to delete the object when done, or will it be deleted in garbage collection? I don't remove any of the listeners except the file loading listeners, just let them run.
(I use this method to avoid problems with scope when I do callbacks -- but I have problems actually passing any information in the object itself -- as I run into scoping issues again, in these callback functions. So usually I just use this and don't even call new Object(), which I assume is OK since I don't use it at the other end, right?
menuBar_mc.left_btn.onPress = function() {
var evtObj:Object;
EventBroadcaster.getInstance().broadcastEvent("leftBtnPressed", evtObj);
I am sure there is a better way to do this, but it seems elegant for file loading, if inelegant for button handling. Still, I've been doing AS 2.0 about a week, and the client is waiting on this, so later I'll go back and figure out a better way).
menuBar_mc.left_btn.onPress = function() {
var evtObj:Object = new Object();
EventBroadcaster.getInstance().broadcastEvent("leftBtnPressed", evtObj);
and I set up the listener
EventBroadcaster.getInstance().addEventListener("leftBtnPressed", this);
which handles it thus
private function leftBtnPressed(evtObj:Object):Void {
var next_pic:Number;
switchPicture(-1);
Do I need to delete the object when done, or will it be deleted in garbage collection? I don't remove any of the listeners except the file loading listeners, just let them run.
(I use this method to avoid problems with scope when I do callbacks -- but I have problems actually passing any information in the object itself -- as I run into scoping issues again, in these callback functions. So usually I just use this and don't even call new Object(), which I assume is OK since I don't use it at the other end, right?
menuBar_mc.left_btn.onPress = function() {
var evtObj:Object;
EventBroadcaster.getInstance().broadcastEvent("leftBtnPressed", evtObj);
I am sure there is a better way to do this, but it seems elegant for file loading, if inelegant for button handling. Still, I've been doing AS 2.0 about a week, and the client is waiting on this, so later I'll go back and figure out a better way).