dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: scroll bar(press and hold)

  1. #1

    scroll bar(press and hold)

    How do I make so when I click and hold on a small MC, it moves another MC down or up, but keeps doing it while the mouse is pressed, but stopps when button is released. Just like regular windows scrolling.

    I just need basic code, I can incorperate, only need to know the method. Basically I cant see where flash knows that the button is down, it can only detect when its been PRESSED, but not that the button is down. can someone show me basic code?

    Thanks for all help
    P4 1.3GHZ|128 RDRAM|DVD 16x|CDRW 12x|Geoforce 2 MX 32MB|WIN XP PRO|56K|IE 6|1024x768
    "Strategery"-George W. Bush

  2. #2
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    You are right, you have to use onEnterFrame() or setInterval() to check over and over again whether the mouse is pressed. Something like this for onEnterFrame():
    code:

    upBtn_mc.onPress = function() {
    target_mc.onEnterFrame = function() {
    this._y += 1;
    } // end onEnterFrame()
    } // end onPress()

    upBtn_mc.onRelease = function() {
    delete target_mc.onEnterFrame;
    } // end onRelease


    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

  3. #3
    So onPress tests if the mouse button is down, not that it was just clicked?

    Thanks
    P4 1.3GHZ|128 RDRAM|DVD 16x|CDRW 12x|Geoforce 2 MX 32MB|WIN XP PRO|56K|IE 6|1024x768
    "Strategery"-George W. Bush

  4. #4
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    You were right the first time: onPress only fires when the button is just clicked, it doesn't test whether it's continuously down.

    The above code causes the illusion of such because when the mouse is pressed down it starts the onEnterFrame function (which starts the target_mc moving). The onEnterFrame() function executes over and over again at the frame rate of your movie, so once you start an onEnterFrame, then each frame will execute the contents of the onEnterFrame. In the code above, each frame will move target_mc one pixel down. Since it's executing every frame, the target_mc will smoothly move down the screen.

    Now, since onPress only fires when the button is just clicked, the onEnterFrame would be started by the button click, but then it would keep on going and target_mc would eventually move off the screen. But I also declared an onRelease() function which is triggered when the button is clicked and then released. So the onPress() fires when the button is pressed down and the onRelease() first when the same button click is released. The onRelease() function deletes the onEnterFrame() function started with the onPress(). Deleting the onEnterFrame() will stop it from executing, so the movement stops.

    So when the mouse is pressed down, the onEnterFrame() starts the target_mc moving, but when the mouse is released, the onEnterFrame() is deleted and the target_mc stops moving.

    This creates the illusion that your button press is being detected as "down", but really it just starts movement when it's clicked and stops the movement when it's released.

    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

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