A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: JBUM, one for you!

  1. #1
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397

    JBUM, one for you!

    We've talk about this...

    How would I get this happening as it is but based on the center of the rectangle, rather than on the left side (xpos = 0), when you test this in the application?
    Hope this is somewhat clear!
    Last edited by oldnewbie; 12-02-2004 at 11:56 PM.

  2. #2
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Is this what you were looking for?

    Nice to see you Old, been a long time since I've been here

    //edit..holy crap, you're almost at 20,000 posts :P

    Adam

  3. #3
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    somehow, when I edited, it deleted my file
    Attached Files Attached Files

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Exactly! Thanks! Now I want it contained within, let's say 50 on the left and 500 on the right!

  5. #5
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    I did this recently for a site, and I put an mc over top of the "hit" area, and tested for the mouse hitting it..would that work?

    I did it here:
    http://www.shavasana.com/flash.html
    the scroll thing at the top

    //edit

    actually, this works, but it's a little sketchy:

    code:

    onClipEvent (load) {
    speed = 5;
    }
    onClipEvent (enterFrame) {
    // reverse mouse coord
    if(_root._xmouse>=50 && _root._xmouse<=500){
    var imx = ((Stage.width/2)+(this._width))-_root._xmouse;
    // convert to ratio (0 - 1)
    _x += (imx-_x)/speed;
    }
    }



    Adam
    Last edited by Adam14; 10-24-2004 at 10:13 PM.

  6. #6
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Maybe... But it would sort of be containing the people in that window, on either side...

    That said there's somewhat awkward in your other file...

    Look at the position of the mouse on the left, when the ball is just leaning on the right border, then the mouse position on the right, when the ball is leaning on the left border... Not the same. Nor does it work the same at all, when screening the .swf?

  7. #7
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Holy crap!! just tested the swf by itself..that is messed up

  8. #8
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Ok, this one works perfect when tested as the swf by itself.

    //edit....or even better, 'cause you're not relying on the start position of the ball:

    code:

    onClipEvent (load) {
    speed = 5;
    }
    onClipEvent (enterFrame) {
    var imx = Stage.width-_root._xmouse;
    _x += (imx-_x)/speed;
    }



    Adam
    Attached Files Attached Files
    Last edited by Adam14; 10-24-2004 at 10:36 PM.

  9. #9
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Pretty good! Curious how it handles in the application...

    Trying to set different left and righ offsets now... Think something is somewhat working...

    Thanks for the help!

  10. #10
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    After how many times you've helped me!!!! Man, I'm happy I could help out

  11. #11
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    this sets limitations:

    code:

    onClipEvent (load) {
    speed = 5;
    }
    onClipEvent (enterFrame) {
    if(_root._xmouse<Stage.width/2){
    var imx = Stage.width-_root._xmouse-50;
    _x += (imx-_x)/speed;
    }else if(_root._xmouse>Stage.width/2){
    var imx = Stage.width-_root._xmouse+50;
    _x += (imx-_x)/speed;
    }
    }


  12. #12
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    I'm just not that good at maths stuff! Never liked maths, and still don't!

  13. #13
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Replying, just to make sure you see my above post before you spend too long on it.

    I was ok with math stuff, but when it comes to as, I just fiddle around until I find something that works...and then I try to figure out what I did

    //edit. nah nevermind, that one messes up if you're right around the center...

  14. #14
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    But it sort of gets sticky if you hover slowly over the middle, no?

    Was just answering the above, while you were posting the above...

  15. #15
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    And why does it seem to jump on that link you posted?

  16. #16
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    arg..just worked on it some more and made even more of a mess of it!! I'm off to bed, good luck with it, oldnewbie

    As far as the jumping on that link, it's a hitTest on a mc over the scroll thing, if you hit it "off center" if reacts according to the script. Not perfect, but you know my experience with flash, surprised I pulled that one off actually

    good luck,
    Adam

  17. #17
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Nighty! Catch you another day maybe!

  18. #18
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Looks like I missed this one. I did the 50-500 thing by replacing this line, in your original:

    endX = _root._xmouse*-ratio;


    with this:

    endX = (500-50)*ratio + 50;

  19. #19
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Cool! Can even change those numbers for different offsets...

    Now, why doesn't this work properly when tested in the application?

    And one last question... What if I wanted it to move according to the mouse's position but not on the whole stage's width... say 20 pixels from either the left or the right border?
    Last edited by oldnewbie; 10-25-2004 at 01:27 AM.

  20. #20
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Basically the trick is getting whatever mouse range you want into ratio (which is a number that must go from 0 - 1.

    So if the desired mouse range is 20 - 50, you would use something like:

    code:

    xm = _root._xmouse;

    // are we in the correct range?
    if (xm >= 20 && xm <= 50) {

    // change scale from 20-50 to 0-1
    ratio = (xm - 20) / (50 - 20);

    // optional step - reverse mouse
    ratio = 1-ratio;

    // change scale from 0-1 to 50-500
    endX = (500-50)*ratio + 50;
    }




    The reverse step causes the mouse to have the opposite effect in that range (e.g. mouse on left pushes object to right).

    Also notice that equation to get the ratio is closely related to the equation to get the endX (they are both scaling operations, which basically involve multiplication or division by a scaling factor).

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