A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How do I set boundaries for a movieclip??

  1. #1
    Member
    Join Date
    Mar 2001
    Posts
    77

    How do I set boundaries for a movieclip??

    I have a movieclip that follows the mouse movement..
    like in my footer
    What code do I use to set up parameters.
    e.g. if(movieclip._x<260)
    stop)
    Say I didn't want my spinning cube to touch the edge..
    Is this right? I know I'm close but I can't get it to work.
    Somebody please help..

    [Edited by itchyfella on 05-03-2001 at 10:06 AM]

  2. #2
    Senior Member
    Join Date
    Jun 2000
    Posts
    145
    you need to set up a 2 frame loop to track where the drag is. in frame one try the following

    if(_root.movieclip._x <0)
    StopDrag

    do the same for the values for top bottom left and right in the first fram, in the second frame you just need a go to and play

    you don't have to do this you can do it with javascript functions but i don't know how thats done

  3. #3
    Member
    Join Date
    Mar 2001
    Posts
    77


    Here is the code I used for the spinning box below... "play" being the box.As you can see I haven't used the startdrag action.. This has really got me stumped.

    onClipEvent (enterFrame) {
    _root.anim.play._x = _root.anim.play._x + (_root.anim._xmouse-_root.anim.play._x)/10;

    Does anyone know how to set up boundaries while using the code above?


  4. #4
    Modding with Class JabezStone's Avatar
    Join Date
    Aug 2000
    Location
    Grand Rapids, MI
    Posts
    2,008
    Can't you just use the boundaries of the startDrag command? You can specify the area that your movie clip is retained in.

  5. #5
    Member
    Join Date
    Mar 2001
    Posts
    77
    When I use the startdrag action and input the boundaries...
    My moviclip disappears which sounds like the co-ordinates are incorrect.. but I've checked it a dozen times,,
    there must be another way..

  6. #6
    Senior Member
    Join Date
    Jun 2000
    Posts
    1,180
    Hi..
    Providing your using the spinning cube scenerio as an example then you can use the following. Place it on the affected MC:

    onClipEvent (enterFrame) {
    if (this._x>300) {
    this._x=300;
    } else if (this._x<100) {
    this._x=100;
    }
    }
    onClipEvent (mouseMove) {
    this._x=_root._xmouse;
    }

    The second part of this code is only there for examples sake, so you can remove that part.

    Hope this helps.

  7. #7
    Member
    Join Date
    Mar 2001
    Posts
    77
    Thankyou Marx...
    You allowed me to go to sleep...
    I would have been up all night otherwise..
    Thats exactly what I was looking for and now I'll know it forever..
    Goodness to you and everyone else that gave a helping typo.
    itchyfella

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