# Scrolling Images Using setInterval & Naming Convention

**URL:** <https://forum.kirupa.com/t/scrolling-images-using-setinterval-naming-convention/284303>\
**Category:** flash\
**Created:** [March 17, 2009, 8:13pm UTC](https://forum.kirupa.com/t/scrolling-images-using-setinterval-naming-convention/284303 "2009-03-17T20:13:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcastro](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fcastro](https://forum.kirupa.com/u/fcastro)\
**Post date:** [March 17, 2009, 8:13pm UTC](https://forum.kirupa.com/t/scrolling-images-using-setinterval-naming-convention/284303/1 "2009-03-17T20:13:12Z")

</div>

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:

```auto

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.
