A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Scrollbar that returns back to its origin..."The Prodigal Scroll bar", if you will..

  1. #1
    Member
    Join Date
    Jul 2000
    Posts
    48
    hello all
    TGIF, first of all, although it probably makes no difference to most of us on this board,
    I have a scroll bar that controls text field. I had an idea where the scroll bar could drag up and down but always return back to the starting point.... In essence creating a rather elastic feeling scroll bar, I was wondering if anyone had done something like that before that wanted to share their knowledge.

  2. #2
    Member
    Join Date
    Jul 2000
    Posts
    48
    Yes, the effect like on http://www.chaotic.co.uk the news section , the arrows it slides and moves back home... this is the effect I was trying to do! anybody have any ideas on how I should approach it?

  3. #3
    Member
    Join Date
    Jul 2000
    Posts
    48

    Hoping someone can help me out

    Anyhow, this is the code I've done so far....the clip/button being dragged returns to the originalposition using the set Property method. I would likd to know how I can get it to return slowly showing the motion. I know it must involve some knowledge of math to do so, anyhow here is the sample code, and hopefully this makes my question little more clear, and your help more focused. mcbtnStar is the movie clip being dragged, and it only drags on Y axis, by 100 pixels up and 100 pixels down from the origin

    -----------------------------------------------------------------------------
    on (press) {
    originalposition = getProperty ( _root.mcbtnstar, _y );
    startDrag ("", false, left, top, right, bottom);
    dragging = true;
    updateAfterEvent();
    }
    on (release, releaseOutside) {
    stopDrag ();
    dragging = false;
    newposition = getProperty ( _root.mcbtnstar,_y);
    if (newposition<>originalposition) {
    setProperty (_root.mcbtnstar, _y, originalposition);
    updateAfterEvent();
    }
    }
    -------------------------------------------------------------------------------

    Thanks

  4. #4
    Junior Member
    Join Date
    Jun 2001
    Posts
    9
    Create an onClipEvent(enterFrame) function that increments the position of the slider if it is not currently being held down until it reaches its original position.

  5. #5
    Member
    Join Date
    Jul 2000
    Posts
    48
    Excellent, yes that confims what i was thnkin, which is good
    but I don't know how to code that, which is bad.
    Could you perhaps enlighten me
    and where would I place that code? On the main stage? or in the movie clip.. Still needing lots of help here.
    Thanks for replying n10si_t

  6. #6
    Junior Member
    Join Date
    Jun 2001
    Posts
    9
    The following assumes that you are running Flash 5 and the movieClip where you are wanting to do the scrolling is not the main timeline (or _root):

    In the first frame of your mcbtnstar clip, put the following code (modified from your original code):

    -----------------------------------------------------------------------------------------------
    originalposition = _root.mcbtnstar, _y;
    dragging = false;

    onClipEvent (mouseDown) {
    startDrag ("", false, left, top, right, bottom);
    dragging = true;
    updateAfterEvent();
    }

    onClipEvent (mouseUp, mouseUpOutside) {
    stopDrag ();
    dragging = false;
    }
    -----------------------------------------------------------------------------------------------



    Then select the movieClip that has your text area and scroll bar and add the following handler:

    -----------------------------------------------------------------------------------------------
    onClipEvent (enterFrame) {
    if ((_root.mcbtnstar.dragging == false) && (_root.mcbtnstar._y != _root.mcbtnstar.originalposition)) {
    _root.mcbtnstar._y++;
    }
    }
    -----------------------------------------------------------------------------------------------

    Hope this helps some.

  7. #7
    Junior Member
    Join Date
    Jun 2001
    Posts
    9
    Sorry... was late last night and I was being distracted when I wrote that (guess that will teach me not to reply to a forum when being distracted ).

    onClipEvent handlers all have to go on an instance of a movieClip. In other words, if you put them on a frame, I think it will tell you it doesn't like that.

    ...so, the modified response:

    In the first frame of your _root clip, put the following code:

    -----------------------------------------------------------------------------------------------
    originalposition = _root.mcbtnstar._y;
    dragging = false;
    -----------------------------------------------------------------------------------------------



    Then select the movieClip that has your text area and scroll bar and add the following handlers:

    -----------------------------------------------------------------------------------------------
    onClipEvent (mouseDown) {
    startDrag ("", false, left, top, right, bottom);
    _root.dragging = true;
    updateAfterEvent();
    }

    onClipEvent (mouseUp, mouseUpOutside) {
    stopDrag ();
    _root.dragging = false;
    }

    onClipEvent (enterFrame) {
    if ((_root.dragging == false) && (_root.mcbtnstar._y != _root.mcbtnstar.originalposition)) {
    _root.mcbtnstar._y++; // or "_root.mcbtnstar._y += 2" or whatever increment makes it fast enough for you
    }
    }

  8. #8
    Senior Member
    Join Date
    May 2001
    Posts
    170
    hey Drewsky,

    I used this type of script many times, here is a little sample:

    http://www.botticelli.cz/files/dragger.fla


    for n10si_t: you have a little error in you code, mouseUpOutside does not exist, onClipEvent(mouse) handlers can not indetify location of cursor, if you want it, you need to use hitTest method:

    onClipEvent (mouseUp) {
    if (!(this.hitTest(_root._xmouse, _root._ymouse, true)}) {
    stopDrag ()
    _root.dragging = false
    }
    }


    You do not need to use updateAfterEvent() with onClipEvent(mouseDown), it will do nothing, updateAfterEvent() is usable for mouseMove handlers for smoother dragging without flickering.

    I can recommend be careful to use onClipEvent(enterFrame). When you have another animated MCs on screen, this handler will make them very slow, and it will never end running, it can not be stopped (you can only to skip script on this handler, but handler will run forever and it will eat part of proccesor performance).
    I made a huge volume of experiments with this handler and I can recommend (abbreviated version of my thoughts): use only one type of animation/calculating script on one frame: do all scripts with enterFrame, or do all scripts with frame-to-frame loops.


    hope this helps
    Alex


  9. #9
    Member
    Join Date
    Jul 2000
    Posts
    48

    Smile

    Thank you both for your replies,
    I will take what you have given me and make a good contribution to the world
    Thank you sweet souls!

  10. #10
    Member
    Join Date
    Jul 2000
    Posts
    48
    Hey, Alex,
    I couldn't get to your website, I think maybe your server is down.. or something teknikal like that....
    Anyhow, i am really interested in seeing your example as I think it is the one that I think I could learn from the best.
    Do you think you might be able to send me a copy of the file through my email address?
    You can view it through the profile on this post, or at dosa34@hotmail.com
    As it is hotmail account, the file cant be larger than 1 mb. But hopefully this will work.
    I will try your site later.
    Thanks Again by the way to you and n10si_t, just seeing that there were replies to my query made me feel very good about the world... Yes, everything is going to be just fine.. just fine indeed.

  11. #11
    Member
    Join Date
    Jul 2000
    Posts
    48

    It's not quite there...

    Not quite sure what the problem is but n10s_t, the code you generously provided is not working.
    I can't figure it out. I have tested the movie and the movieclip Mcbtnstar, starts scrolling as soon as the movie loads..... not quite sure what the problem is, but i will try some other stuff and post it on.

  12. #12
    Senior Member
    Join Date
    May 2001
    Posts
    170
    hey, drewskii

    I sended you an email with file, let me know you if obtained it OK ot not!

    there are some little errors in n10s_t codes, I think after some little changes it will work very good too.


    Alex

  13. #13
    Member
    Join Date
    Jul 2000
    Posts
    48
    Thumbs UP Alex!
    Got your file just fine, and it is looking very proper.
    Thanks and I will let you know how my experimentation is going.
    Cheers!

  14. #14
    Junior Member
    Join Date
    Jun 2001
    Posts
    9
    First off:

    Alex, thank you for the pointers. They are taken to heart and put to use.

    Drewskii, let me take another shot at this...

    I realized that when you set the originalposition variable in the _root timeline, mcbtnstar has not loaded yet. So it starts scrolling immediately because _root.mcbtnstar._y is undefined on the frame where originalposition is first set. I also had not realized that you had set up mcbtnstar as a button rather than a movieClip. I think it would be easier to follow Alex's note of avoiding enterFrame scripts if you make mcbtnstar a movieClip and have it loop. If you still need it to have some kind of rollover/mouseDown effect, you can still embed those effects in a button inside this movieClip.

    Let's try the following with my head a little clearer and taking in Alex's advice:


    On the first frame of mcbtnstar, put the following script:
    -------------------------------------------------------------------------------------------
    originalposition = this._y;
    dragging = false;
    -------------------------------------------------------------------------------------------

    On frame 2:
    -------------------------------------------------------------------------------------------
    if ((dragging == false) && (this._y >= originalposition)) {
    this._y--; // or "_root.mcbtnstar._y -= 2" or whatever increment makes it fast enough for you
    }
    -------------------------------------------------------------------------------------------

    On frame 3:
    -------------------------------------------------------------------------------------------
    gotoAndPlay(2); //it is important that you skip the first frame so that you are not resetting your variables.
    -------------------------------------------------------------------------------------------

    On the mcbtnstar when selected in _root:
    -------------------------------------------------------------------------------------------
    onClipEvent (mouseDown) {
    trace(this);
    this.startDrag (false, left, top, right, bottom); //this is presuming that these are variables you are setting
    this.dragging = true;
    }

    onClipEvent (mouseUp) {
    if (!(mcbtnstar.hitTest(_root._xmouse, _root._ymouse, true))) {
    this.stopDrag ()
    this.dragging = false
    }
    }
    -------------------------------------------------------------------------------------------

    I have set this up in Flash and it seems to work for me. Thanks again to Alex (I would be curious to communicate with you via email) and good luck... sorry for all the dead leads.

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