A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: onRollOver function for non-button MC?

  1. #1
    Learn more, know less.
    Join Date
    Jul 2004
    Posts
    169

    onRollOver function for non-button MC?

    Hey, this seems like there would be an easy solution, but I obviously am not aware of the syntax.

    I am loading an external MC underneath a series of MCs in the main swf. I want the main MCs to fade to 50% when the mouse goes over them (to see what's under) but I can't use buttons to accomplish this, because the underneath layer has buttons in it that need to function at the same time.

    Suggestions for an onRollOver method for non-button MCs?

  2. #2
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    You could use coordinates and width and height if your MC is rectangular, or even hitTest to detect if the mouse is hitting your object:
    code:
    yourMC.state = 0;
    yourMC.onEnterFrame = function()
    {
    if (yourMC.hitTest(_xmouse, _ymouse) && !yourMC.state)
    {
    yourMC.state = 1;
    trace("over");
    }
    };

    The "yourMC.state" stuff is to make your if-statement true only when you rollover the MC, and not true all the time your mouse is over the clip. Then you need a rollout function though to set yourMC.state back to 0.
    code:
    yourMC.state = 0;
    yourMC.onEnterFrame = function()
    {
    if (yourMC.hitTest(_xmouse, _ymouse))
    {
    if (!yourMC.state)
    {
    yourMC.state = 1;
    trace("over");
    }
    } else if (yourMC.state)
    {
    /* This is your rollOut function */
    trace("out")
    yourMC.state = 0;
    }
    };

    Last edited by Dricciotti; 08-20-2005 at 08:34 PM.

  3. #3
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    actually, to the best of my knowledge. You can add the onRollOver, onPress, etc. functions right onto an normal movieclip.

    ex. movieclip.onRollOver = function() {
    //rollover function
    }
    movieclip.onPress = function() {
    //press
    }
    Nothing to see here, move along.

  4. #4
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    Currect. but he has buttons undernearth his movie clip and wanted an alternative to using button properties on the MC.

  5. #5
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    Quote Originally Posted by Dricciotti
    Currect. but he has buttons undernearth his movie clip and wanted an alternative to using button properties on the MC.
    thats weird. there has go to be a better way of doing that.
    Nothing to see here, move along.

  6. #6
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    The problem is that if you have two buttons on top of eachother, only the top one works when you roll over it. I made a site a while ago that had different windows (like in an OS) that would be in front of eachother and when you click on any part of a window it was brought to the front. The problem I ran into was that my windows had buttons of there own so giving the window button actions and giving my buttons actions gave me a conflict. I used a similar solution to the one posted above and havent really seen anything better (although I never looked for one).

  7. #7
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    Quote Originally Posted by Dricciotti
    The problem is that if you have two buttons on top of eachother, only the top one works when you roll over it. I made a site a while ago that had different windows (like in an OS) that would be in front of eachother and when you click on any part of a window it was brought to the front. The problem I ran into was that my windows had buttons of there own so giving the window button actions and giving my buttons actions gave me a conflict. I used a similar solution to the one posted above and havent really seen anything better (although I never looked for one).
    actually, i would have used a "window active" variable to automatically turn buttons on/off.
    Nothing to see here, move along.

  8. #8
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    This was a while ago, back before I was so suave with actionscript. What I did was have all the windows have an instance name of "pop"+their depth and then when the mouse was pressed, I would run a for-loop starting with the highest depth and work my way down. Once I found a window whose hitTest was true, I stopped the for-loop and brought that window to the top. Then, seperatly from that I had a setInterval function that continuosly checked if the windows was active and would disable or enable the appropriate buttons. Here the code if anyone wants to see what im talking about. Again, this was done a while ago and isnt the most efficient way.

    I also spent a good deal of time making sure that little glitches werent in my movie. Like if you had a window partly above another and a button on that bottom later and you rolled over the button in a spot where the bottom window wasnt covered then staying on top of the button moved the mouse to the covered part of the button, the "hand" cursor would still show up. And I didnt like that.

    code:
    onMouseDown = function () {
    mouseX = _root._xmouse;
    mouseY = _root._ymouse;
    for (q=tier; q>=2; q--) {
    cName = _root["pop"+q];
    if ((mouseX>cName._x) && (mouseX<cName._x+cName.WIDTH) && (mouseY>cName._y) && (mouseY<cName._y+cName.HEIGHT)) {
    /* Should have used hittest */
    if (q != tier) {
    tier++;
    cName.swapDepths(tier);
    cName._name = "pop"+(tier);
    }
    q = 1;
    }
    }
    };
    var looker_control = setInterval(looker, 30);
    function looker() {
    found = false;
    for (q=tier; q>=2; q--) {
    xm = _root._xmouse;
    ym = _root._ymouse;
    rx = _root["pop"+q]._x;
    ry = _root["pop"+q]._y;
    if ((found == false) && (xm>rx) && (xm<rx+_root["pop"+q].WIDTH) && (ym>ry) && (ym<ry+_root["pop"+q].HEIGHT)) {
    _root["pop"+q].enable = true;
    found = true;
    } else {
    _root["pop"+q].enable = false;
    }
    }
    }


  9. #9
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    are you talking to me now, cause i know how todo all of this stuff. JoelTHE is the thread owner and he hasn't been here yet.
    Nothing to see here, move along.

  10. #10
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    post# check.
    Nothing to see here, move along.

  11. #11
    Learn more, know less.
    Join Date
    Jul 2004
    Posts
    169
    You guys are smart.

    The hit test is a good idea, and I'm a little disappointed in myself for not thinking of that. I got so bogged down in the whole site I forgot about that option. Thanks.

    Is the "state" property something built into the MC object by default? It seems that way by the way you're using it, I've just never used it. It looks like a value of 0 returns false, and a value of 1 returns true, yes? Like, 0 is inactive and 1 is active?

    If you could spare a minute to explain that a little more I would appreciate it. Thanks for this discussion though; even the not-as-relevant window depth/buttons part was interesting.

  12. #12
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    The state variable was just something I made, not a property.

    Quote Originally Posted by JoelTHE
    Is the "state" property something built into the MC object by default? It seems that way by the way you're using it, I've just never used it. It looks like a value of 0 returns false, and a value of 1 returns true, yes? Like, 0 is inactive and 1 is active?.
    Yes.

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