A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: my=_root._ymouse;

  1. #1
    Senior Member
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    164

    my=_root._ymouse;

    Hello friends.

    I have created with the help of the tutorials of Flash Kit, a rectangle that follows the y axis leads of my mouse. I also have a box that I would like the rectangle to be bordered by. As it stands the rectangle will follow the mouse outside of the box which is NOT what I am looking for. I have search extensively for a tutorial of some sorts that works with borders or something to that effect to no avail. Could someone, when they have time help me keep the rectangle within the box. The box is apparent. I thank you all in advance.

    click here for the webbed example

    click here for the zip of the files associated


    London.

  2. #2
    Senior Member
    Join Date
    Oct 2001
    Posts
    1,053
    all you need is some if statements... heres how you do it.

    for an example lets say you want the rectangle to go no higher then 200, and no lower then 500. lets say the box instance name is just "box"

    just add this code to the rest of your code...

    if (_root.box._y<200){
    _root.box._y = 200;
    }
    if (_root.box._y>500){
    _root.box._y = 500;
    }

    these simply state that if the box's _y coordinates are greater than 500, the _y coordinates = 500, and the same for the 200.

    all you have to do is change the _root.box to whatever your mc's instance name is.
    to set these for the _x axis just change the _y's to _x's and change the numbers.

    hope that helps

  3. #3
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Yeah! Like he said!

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Or... To be a little more precise:

    onClipEvent (enterFrame) {

    //y movement
    my=_root._ymouse;

    if (my <= 112){
    my = 112; // Or something closer...
    }
    if (my >= 456){
    my = 456; // Or something closer...
    }

    if (my<_y) {
    dy=_y-my;
    }
    else {
    dy=my-_y;
    }
    moveSpeedy=dy/2;
    if (my<_y) {
    _y=_y-moveSpeedy;
    }
    else {
    _y=_y+moveSpeedy;
    }
    }

  5. #5
    Lord of the Singhs
    Join Date
    Mar 2002
    Location
    India
    Posts
    342
    or u cud use hitTest perhaps... i am not sure... don't want to confuse u or anything but i wud like to know if everyone thinks that is a viable solution??
    CooL "N" CalM

    my body is sore
    my eyes are red
    i still itch for more
    before i hit the bed

  6. #6
    Senior Member
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    164
    well I must say, I must say, THANKS..!!!

    any more ideas would be great too but for now this little bit of help really did help. Thanks again gentlemen : )


    London.

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