[Flash 8] Dynamic Instance Names

Hi, I am doing a school project (a timeline) involving 5 individual timelines (“soc_time”, “tech_time”, “env_time”, “eco_time”, “pol_time”) on a single, main timeline (“timeline”) that moves with the left and right cursor keys. “Timeline” has lines at 200 pixel intervals for reference (10 years = 200 pixels). There are 5 thumbnails at the bottom (“soc_thumb”, “tech_thumb”, etc.) and when you click on one, it makes the sub-timeline (“soc_time”, “tech_time”, etc) appear using timeline.attachMovie (i.e. when you click on “society” at the bottom the society timeline (“soc_time”) appears on the main timeline). Inside each sub-timeline (“soc_time”, etc.) there are dates (“soc_1900”, “soc_1904”, etc) (no attachMovie involved here, they are already in the sub-timeline). When you click on these dates, a window pops up with more information on that date (“win_soc_1900”, etc)

What I need to do is simplify/cleanup my code, because now it is over 750 lines, and I know there is a way to make it shorter. Ultimately, my best idea involves writing a function that takes “soc_1900”'s, “soc_1904”'s, etc.'s _x position relative to the sub-timeline it is nested in (“soc_time”). I want to take the _x positions, divide by 20 and add 1900 which would give me the date it is.

What I have now is this:


_root.onMouseDown = function() {
        if (timeline.soc_time.soc_1900.hitTest(_xmouse, _ymouse, true) && !window_soc_1900) {
            _root.attachMovie("_win_soc_1900", "win_soc_1900", 101);
            window_soc_1900 = true;
            setProperty(win_soc_1900, _x, 85);
            setProperty(win_soc_1900, _y, 95);
            setProperty(this, _alpha, 80);
        }
        if (timeline.soc_time.soc_1913.hitTest(_xmouse, _ymouse, true) && !window_soc_1913) {
            _root.attachMovie("_win_soc_1913", "win_soc_1913", 102);
            window_soc_1913 = true;
            setProperty(win_soc_1913, _x, 85);
            setProperty(win_soc_1913, _y, 95);
            setProperty(this, _alpha, 80);
        }
};
//ad infinitum

As I said, this works fine, but what I want to do is something like this:


var windows:Boolean = false;
function socClick() {
    if (this.hitTest(_xmouse, _ymouse, true) && !windows) {
        _root.attachMovie("_win_soc"+this._x/20+1900, "win_soc_"+this._x/20+1900, getNextHighestDepth());
        windows = true;
        setProperty("win_soc_"+this._x/20+1900, _x, 85);
        setProperty("win_soc_"+this._x/20+1900, _y, 95);
        setProperty("win_soc_"+this._x/20+1900, _alpha, 80);

    }
};
_root.soc_1900.onMouseDown=socClick();

I just can’t get this to work, hence this thread.

Working on uploading an swf.