Need help connecting looped programmatic tweens to their onMotionFinished events

I’ve been an amateur programmer of various sorts for 12 years now, and this is my first posting EVER to a forum. Exciting.

I have gotten pretty deep into actionscript but I fear my lack of formal training is finally starting to catch up with me.

I’m working with the Tween object: I’m building a game where mc’s need to drop periodically from the sky, and then when they reach the bottom of the screen, they need to be unloaded. The problem I’m having is firing “onMotionFinished” events for these dynamically, “loop-generated” mc’s. I think I need to be able to send parameters to an onMotionFinished function, but I can’t figure out how. I made a stripped-down version of what I’m doing, here’s the code:


import mx.transitions.Tween;
import mx.transitions.easing.*;

//this keeps track of which bomb we're on
bomb_count = 0;

//drop a bomb every second
bomb_interval = setInterval(drop_bomb,1000);

function drop_bomb() {
    bomb_count++;

    //create the bomb (just a simple movie clip with its linkage value set to "bomb_mc"
    _root.attachMovie("bomb_mc","bomb"+bomb_count,bomb_count);
    
    //this makes it so the bombs don't all fall in the same place
    _root["bomb"+bomb_count]._x = bomb_count * 100;
    
    //drop it
    var tween_fall:Object = new Tween(_root["bomb"+bomb_count], "_y", Strong.easeOut, 0, 300, 24, false);
    
    //this is what I'm not doing right...
    tween_fall.onMotionFinished = function() {
        explode_bomb(bomb_count);
    }
    
}

function explode_bomb(bombID) {
    //these both return the same value, which means
    //the "bombID" for the "current" bomb is being passed in 
    //rather than the the ID for the one that just got to the bottom.
    trace(bombID);
    trace(_root.bomb_count);
    
    //this is unloading the mc that just started tweening,
    //rather than the one that just stopped
    unloadMovie(_root["bomb"+bombID]);
}

Basically I just want to have more control over the programmatic tween and its associated events. Everything is there, it’s just that the onMotionFinished event isn’t attached to the tween I want it to be attached to, it’s attached to the most recent tween that occured, or something. I suspect it has something to do with the fact that all my tweens have the same name, but I don’t know how to name them differently in the loop.

I read some stuff about “delegates” and “superclasses” and other dizzying objecty things that seemed relevant but like I said, since I’m not oop fluent, I get pretty lost pretty quick, esp. since I couldn’t find a discussion that was directly related to my problem. Anyone have any down-to-earth, straightforward advice? Or maybe at least direct me in some direction as far as what I should study to get a better grip on this?

Thanks,
Jerome