A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Image moving around - detecting border of SWF and bouncing

  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    3

    Image moving around - detecting border of SWF and bouncing

    Hi there, I am a bit of a newbie here and I've got a very silly problem. I've got an image moving around my SWF depending on what side of the .swf file the mouse cursor is.

    Here it is: http://supr.is-a-geek.org/psd/flash.html

    The problem is prolly very obvious: the image disappears when it should detect the border of SWF and bounce back.

    here is the script for moving aorund:
    code:

    onClipEvent (load) {
    x = 0;
    }
    onClipEvent (enterFrame) {
    this._x += x;
    if ((_root._xmouse>0) && (_root._xmouse<50)) {
    if (x>-3) {
    x -= 0.15;
    }h
    }
    if ((_root._xmouse>715) && (_root._xmouse<765)) {
    if (x<3) {
    x += 0.15;
    }
    }
    }



    Any help would be much appreciated. Thanks!

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    code:

    onClipEvent (load) {
    x = 0;
    // you'll need to adjust both of these quantities.
    minX = -400; // minimum value for this._x
    maxX = 400; // maximum value for this._x
    }

    onClipEvent (enterFrame) {
    if (x < 0)
    {
    if (this._x + x < minX) this._x = minX;
    else this._x += x;
    }
    else if (x > 0)
    {
    if (this._x + x > maxX)this._x = maxX;
    else this._x += x;
    }
    // simplified these...
    if (_root._xmouse<50) {
    if (x>-3) {
    x -= 0.15;
    }
    }
    if (_root._xmouse>715) {
    if (x<3) {
    x += 0.15;
    }
    }
    }

    Last edited by jbum; 10-16-2004 at 01:18 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    3
    Yay! It works and I even understand it! =) Thanks a lot!

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