A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help needed: Nested mc controlled by mouse position

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    2

    Help needed: Nested mc controlled by mouse position

    Please help me with this if you can:

    in root i have a MC named mc0; nested within it is another MC named mc1. Both have "stop();" in the first frame, but only the second (the nested one) contains an animation, in two parts: first part is from frame 1 to 10 and the second one (the reverse) from 11 to 20. I want mc1 to play the first part when the mouse enters a certain area, and the second one when the mouse exits the area. This is the main idea.

    The only way that worked it was when I made two movie clips with the two parts of the animation (i split the nested movie in two mcs), and put them in m0, one in the second frame, one in the third; the first frame of m0 was stopped. So, for this, i put the following AS on mc0:

    onClipEvent (enterFrame) {
    if (_root._xmouse > 156 && _root._ymouse > 416) {
    this.gotoAndStop(2);
    }
    else{
    this.gotoAndStop(3);
    }
    }

    It works like this, but I need the animation to be in only one mc (mc1), that I`m gonna nest in different parts of the main movie.

    So I thought that the best for my needs would be to use something like: mc0 contains mc1, and on mc1 put this AS in the first frame:

    stop;
    onEnterFrame = function(){
    if (_root._xmouse > 156 && _root._ymouse > 416) {
    gotoAndPlay(nextFrame);
    }
    }

    so, when mouse enters the defined area, mc1 should play (?) until it reaches frame 10 where I have another script:

    onEnterFrame = function(){
    if (_root._xmouse > 156 && _root._ymouse > 416) {
    stop;
    }
    else{
    gotoAndPlay(nextFrame);
    }
    }

    that means that if the mouse stays in the area, the animation stops on frame 10. if the mouse leave the area, it should advance (with the reverse animation in fact), until it reaches frame 20, that is a keyframe with:

    gotoAndStop(1);

    It doesn`t work.

    In fact I tried many other versions, some of them stop on frame 2, some of them just play the whole animation from 1 to 20 without any stop and without any concern of the position of my mouse. I`m totally confused and I can`t explain better that this.

    I must admit that I`m a beginner in AS, and it might be something obvious for an advanced user that i

    didn`t know or I would have never thought about. That`s why I`m here.

    So help me if you can.
    Thank you,
    M.


    (I use Flash Professional 8, AS 2.0)

  2. #2
    Member
    Join Date
    Mar 2006
    Posts
    30

    control MC by mouse position

    A sample file or link would help more, I think.

    is this the effect you were looking for? (see attached fla)

    everything is done in code on the actionscript layer. I made a big green sensor clip just so you could see it - you could set it's alpha to 0 or the same code would work with a bunch of "is the mouse here and here" code like you have currently.

    sensor_mc is just a simple movieclip with a green rectange in it, when you rollover it with the cursor the hitTest becomes true and it makes the grapher_mc play with nextFrame, when you roll off it plays backwards with prevFrame

    If you are just reversing the direction of a tween or animation you shouldn't have to remake the animation in reverse, play it in reverse with repeated prevFrames

    It is also a "best practice" to add instance names to objects on the stage and program them from a keyframe on an actionscript layer instead of attaching code to an instance of that item on the stage.


    code:
    Code:
    sensor_mc.onEnterFrame = function() {
    	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    		_root.grapher_mc.nextFrame();
    	} else {
    		_root.grapher_mc.prevFrame();
    	}
    };
    Attached Files Attached Files

  3. #3
    Junior Member
    Join Date
    Mar 2006
    Posts
    2

    Thanks

    In fact I posted this question on other forums too. From the other ones it was only one working, but you gave me the best solution. Definately I have to learn ActionScript better! It was so simple! ...

    Thank you very much, merkurious!

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