Scrolling Images Using setInterval & Naming Convention

Hi everyone,

I am looking at a sample sliding image flash file that uses setInterval and rollOvers etc. I noticed that the author named his instances as numbers which isn’t allowed. I don’t even understand how he was able to do it unless he used an older version of flash. CS won’t let you name an instance starting with a number.

He has 5 instances on the main timeline all named “1” thru “5”. I figured I would try to rectify the problem by changing the actions and of course changing the name of the movieclips to “mc_1” thru “mc_5”. I ran into some logic problems because his script relies on using the _name property of the clip in order to correctly select the active button when the user rollOver it.

For example, if I rollOver the 3 button the rollover = this._name property apporiately equals “3” which is simple. But when I tried to change it via a variable so that it equals “mc_3” well I have run into a problem because obviously 3 is a number while mc_3 is a string.

Here is the original code:


image_slider.onEnterFrame = function() {
    var _counter = this;
    _counter.x_target = -(rollover - 1) * 352 + 576;
    _counter._x = _counter._x + (_counter.x_target - _counter._x) / 7;


};

image_amount = 5;

interval_setter = setInterval(rotate, 3000);

function rotate() {
    if (rollover == image_amount) {
        rollover = 1;
    } else {
        rollover++;
    }
}

rollover = 1;

for (i = 1; i <= image_amount; i++) {

    this*.onRollOver = function() {
        rollover = this._name;
        clearInterval(interval_setter);
    };
    
    this*.onRollOut = function() {
        interval_setter = setInterval(rotate, 3000);
    };
    
    this*.onEnterFrame = function() {
        var _counter = this;

        if (_counter._name == rollover) {

            _counter.gotoAndStop(2);

        } else {

            _counter.gotoAndStop(1);
        }
    };
}

stop();


In order to fix the instances I changed the labels of the instances to “mc_1” etc. I then created a variable called “mc” which bascially added the string “mc” + i which would give me the correct path “mc_1” etc for all the instances. Only problem now is since the script revolved on using the name property as a number, I have not been able to remove the "mc" part when the script says rollover = this.name. I tried creating another variable called mcSubstring that removed the "mc" part using the substr method but then I was just seeing 5 all the time and nothing else on rollOver.

Anyone have any feedback here? I stepped through the script line by line and can’t think of any other creative way to fix it.