Flash AS snippet is no use for my case

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Flash AS snippet is no use for my case

Post by Sindarin »

A friend shared an AS snippet with me for a banner I want to make. It slides 3 movieclips called "tab" (tab0,tab1,tab2,tab3) along the side when you rollover on each. However I need more than 3 movieclips, but when I created a new one and named it tab4, the script stopped working.

Use this code at the first frame:

Code: Select all

stop ();
state = new Array(false, false, false, false);
media = Stage.width / (state.length + 10);
minimum = (Stage.width - tab0._width) / (state.length - 1);
maximum = tab0._width;
MovieClip.prototype.move = function (goal, speed)
{
    var _loc1 = this;
    _loc1.arrive = false;
    _loc1.onEnterFrame = function ()
    {
        var _loc1 = this;
        _loc1._x = (goal - _loc1._x) / speed + _loc1._x;
        if (Math.abs(goal - _loc1._x) <= 5.000000E-001)
        {
            _loc1._x = goal;
            _loc1.arrive = true;
            delete _loc1.onEnterFrame;
        } // end if
    };
};
for (i = 0; i < state.length; i++)
{
    this["tab" + i].onRollOver = function ()
    {
        ind = this._name.substr(3, 1);
        state[ind] = true;
    };
    this["tab" + i].onRollOut = function ()
    {
        ind = this._name.substr(3, 1);
        state[ind] = false;
    };
} // end of for
heads = function ()
{
    result = -1;
    for (i = 0; i < state.length; i++)
    {
        if (state[i])
        {
            result = i;
        } // end if
    } // end of for
    return (result);
};
_root.onEnterFrame = function ()
{
    var _loc1 = this;
    heads_hnd = heads();
    if (heads_hnd != -1)
    {
        for (z = 0; z < state.length; z++)
        {
            if (z <= heads_hnd)
            {
                _loc1["tab" + z].move(z * minimum, 20);
                continue;
            } // end if
            _loc1["tab" + z].move(z * minimum + maximum - minimum, 20);
        } // end of for
        return;
    } // end if
    for (z = 0; z < state.length; z++)
    {
        _loc1["tab" + z].move(z * media, 10);
    } // end of for
};
 
 
I tried changing:

ind = this._name.substr(3, 1);

to:

ind = this._name.substr(4, 1);

but still it doesn't work.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Flash AS snippet is no use for my case

Post by arjan.top »

maybe?

state = new Array(false, false, false, false, false);

Just quick look at the code ...
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Flash AS snippet is no use for my case

Post by Sindarin »

I can't believe I missed that.

Thanks, it works now..
Post Reply