A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: MC._alpha changes depending on mouse pos.

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    hi all. I'm fighting with a script that should be simpler than that! here's the story:
    in the center of a 600/400 pixels movie is a MC called _root.box. when the mouse is over it its alpha is at 100. and at the edges of the movie the box alpha is at 0. I was able to do it on _x axis. but i'm sure there is a simpler way so that it could react to the _y axis too.
    here's the code i made up for the x axis:
    onClipEvent (enterFrame) {
    _root.mouse = _root._xmouse;
    _root.center = 300;
    _root.boxalpha = (_root.mouse-_root.center)*(_root.mouse-_root.center)/1000;
    }
    onClipEvent (mouseMove) {
    setProperty ("_root.box", _alpha, Math.sqrt((_root.boxalpha-100)*(_root.boxalpha-100)));
    }
    It can be simpler i'm sure!!!
    any help will be very much appreciated!
    G.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Posts
    2,235
    Say your box is 300x300.

    _root.xm = _root._xmouse;
    _root.ym = _root._ymouse;

    _root.xc = // center of the box on x
    _root.yc = // center of the box on y

    _root.x = Math.abs(_root.xm - _root.xc)
    _root.y = Math.abs(_root.ym - _root.yc)

    result = Math.sqrt((_root.x*_root.x)+(_root.y*_root.y));#

    final = 300/result; // you can play around with these numbers to fine tune them.

    _root.box._alpha = final;

    #or maybe better (and simpler) would be;
    result = _root.x+_root.y

    ~mgb
    [Edited by mgb on 05-16-2001 at 02:37 AM]

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Location
    Sydney, Australia
    Posts
    271
    G'Day,

    What about..

    xPosMid = //middle of box _x

    smallX = //left hand edge of box _x

    xScale = (xPosMid - smallX) / 100;

    if (_xmouse < xPosMid)
    {
    box._alpha = 100 - ((xPosMid - _xmouse) / xScale);
    }else if (_mouse > xPosMid)
    {
    box._alpha = 100 - ((_xmouse - xPosMid) / xScale);
    }


    Obviously you do the same for the y axis then just find the average of the two alphas by adding them then halving them.

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    thanks! actually i found that script from leo lima in the archive of this forum. The script works fine:
    onClipEvent (load) {
    w = 600/2;
    // the movie width /2
    h = 400/2;
    // the movie height /2
    maxdist = Math.sqrt((w*w)+(h*h));
    // the maximum distance that the mouse can be
    step = 100/maxdist;
    // the constant that defines the alpha stepping
    }
    onClipEvent (enterFrame) {
    // Calculate the distance of the mouse:
    x = Math.abs(this._x-_root._xmouse);
    y = Math.abs(this._y-_root._ymouse);
    dist = Math.sqrt((x*x)+(y*y));
    // Apply the alpha change:
    this._alpha = 100-(dist*step);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center