SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    Also available in Large Si's Avatar
    Join Date
    Sep 2002
    Location
    Walsall, UK
    Posts
    1,911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with buttons

    I've got two buttons that rotate a movie clip clockwise and anti-clockwise. At the moment, they only rotate a step at a time while the mouse button is held down but I want them to continuously rotate while the mouse button is held down.

    I'm using Flash MX and the current code is as follows:

    Code:
    on(press) {
     // rotate the protractor anti-clockwise.
     protractor._rotation += -1;
    }
    (obviously, the value is '1' for clockwise)

    Can anyone help with this? It's quite urgent to get this done so the timer's ticking...

    Cheers very much!
    Si
    Are you a Photoshop Jedi Master? Prove it!

    Is funky house your bag? You'll love this!

    Voice
    , eyes, ears, body and hands.


  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah you will need to use an enterframe handler. Are you using Flash MX?

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the MX code

    Code:
    buttonInstance.onPress = function() {
      this.onEnterFrame = rotClockwise;
    }
    buttonInstance.onPress = function() {
      this.onEnterFrame = null;
    }
    function rotClockwise() {
      protactor._rotation += 1;
    }
    Then just repeat for the counterclockwise one. Where buttonInstance is the intsance name assigned to the button.

  4. #4
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    freddy, will your code work?

    Just wondering but shouldn't you define functions before you place code that could use it?

    ie, if buttonInstance was pressed, it would reference to call a function that has not yet been defined (rotClockwise)
    Code:
    function rotClockwise() {
    protactor._rotation += 1;
    }
    buttonInstance.onPress = function() {
    this.onEnterFrame = rotClockwise;
    }
    buttonInstance.onPress = function() {
    this.onEnterFrame = null;
    }

  5. #5
    Also available in Large Si's Avatar
    Join Date
    Sep 2002
    Location
    Walsall, UK
    Posts
    1,911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the help guys... I've got it all working now using a different method.

    Code:
    on(press) {
    _root.protractor.onEnterFrame = function(){
    _root.protractor._rotation -= 1;
    }
    }
    on(release){
    delete _root.protractor.onEnterFrame;
    }
    Si
    Are you a Photoshop Jedi Master? Prove it!

    Is funky house your bag? You'll love this!

    Voice
    , eyes, ears, body and hands.


  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool

    Aaron,

    Did you happen to test this before asking that question? If you had, you would have seen that it does in fact work, the function is declared as the soon as the frame loads.

    The only mistake I had was the onRelease was an onPress and needed changning, other than that it worked fine with the function below the event handlers.

  7. #7
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    lol

    Yes I did. You had more errors than that. Your function call of this.onEnterFrame = rotClockwise; does not work unless you call it rotClockwise();

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol

    Yes I did. You had more errors than that. Your function call of this.onEnterFrame = rotClockwise; does not work unless you call it rotClockwise();

    I can tell you tested it then , because you should not have the () after the function name when assigning an event handler.

    In fact if you add the () like you have shown the function will only run once, it will not run at the frame rate. So yes the onRelease was the only oversight. I am curious as to how you came up with that the () should be there if you really tested it.

  9. #9
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Without that () the script was not run at all.

    With the () the script was run During the press event handler once which is what I would expect since said function was now uncallable since the Release function changed to button's functionality to nothing (null)

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without that () the script was not run at all.
    I disagree.
    With the () the script was run During the press event handler once which is what I would expect since said function was now uncallable since the Release function changed to button's functionality to nothing (null)
    Actually what they want to happen is for the clip to continue rotating until the button is released. So running it once is fine but not they want.

    Maybe you are not understanding what is meant by dynamic assignment of event handlers. When the onPress handler is called the clip's onEnterFrame event is assigned to function rotClockwise, so as long as the button is held down, the function runs as many times per second as the movie's frame rate. Once they release the button the onEnterFrame event is removed from the clip, and once they press it again the same thing happens again.

    HEre see what I mean.
    http://www.irq11.com/~louie/especially4aaron.html

    http://www.irq11.com/~louie/especially4aaron.fla

  11. #11
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Here's the code

    Code:
    buttonInstance.onPress = function() {
      this.onEnterFrame = rotClockwise();
      // the above line will not work if () is removed
    }
    buttonInstance.onRelease = function() {
      this.onEnterFrame = null;
    }
    function rotClockwise() {
      protactor._rotation += 1;
    }
    If you remove the () on line 2, the script DOES NOT WORK. I don't know why you're giving me such an attitude on this. I placed the code in Flash MX, TESTED IT, and if you leave () off, the pressing of button named buttonInstance does NOT rotate the MC named protactor. If it is added, then clicking the button DOES rotate the MC.

  12. #12
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    LOL. I didn't say that it was being called multiple times. I only stated "Your function call of this.onEnterFrame = rotClockwise; does not work unless you call it rotClockwise(); "

    That statement is true. I know that with my above code, the addition of () only makes it perform once, that wasn't my point; my point alone is that with said code, the function won't even call if rotClockwise is used without the parentheses.

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why am I giving you attitude? Well let me ask you this, did you download the fla I linked in my last post? Did you open it in MX? Did you run the movie? Did it work? I would be very much interested to know the answers, because I am staring at the swf right now with no () and it works fine.

  14. #14
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You on a MAC or PC?

  15. #15
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PC.

    I found the problem. If you make the Button, a BUTTON (like I have), then the code used works in the manner I specified, and to a T.

    If you make the Button a MOVIECLIP object, then it works in the manner you specified.

  16. #16
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it to work with being a button as well. Not sure why there is an inconsistency between what I am seeing and what you are seeing.

    http://www.irq11.com/~louie/especially4aaron2.html
    http://www.irq11.com/~louie/especially4aaron2.fla

  17. #17
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm not much on caring that it works in both methods. I'm well aware that flash mx has about 20 different ways to do one thing. My goal was to find the key factor why your script and my script acted in different behaviors (even after being tested)

    I only assumed they were buttons because the initial post said they used buttons. And strictly saying, we both know that MovieClips are not Buttons. This is just miscommunication; though I still didn't care for the attitude.

    The net is such a vast medium of information, that miscommunication is sure to happen sooner or later; how it is dealt with will prove the end result to be either negative or positive.

  18. #18
    Also available in Large Si's Avatar
    Join Date
    Sep 2002
    Location
    Walsall, UK
    Posts
    1,911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys...

    I just want to say thanks for the all help in this. You've obviosuly gone to a lot of trouble trying to find the best solution and the perfect bit of code.

    I've resolved the said problem now anyway... good discussion though. Make's you realise how picky Flash (MX or otherwise) can actually be. I've noticed that too during the development of my Flash application.
    Si
    Are you a Photoshop Jedi Master? Prove it!

    Is funky house your bag? You'll love this!

    Voice
    , eyes, ears, body and hands.


  19. #19
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry that you feel that way. There is still an issue, as you say with a button it works your way. Well I am here to tell you that with a button it works the same. I have provided you with both a version using a movieclip as psuedo button and one with an actual button. Both of them work with the initial code I provided.

    I am sorry you don't like my attitude, but thats me, and you'll have to learn to accept it or just ignore me. Whichever you prefer.

  20. #20
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'll have to learn to accept it? Sorry to disappoint, but I don't have to do anything I don't want to. Keep your attitude freddy, you'll make tons of friends with it.

  21. #21
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Only a lesson when you learn from it.

  22. #22
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    lol. You're on the ignore list Flintstone, I have no idea what you're babbling on about now. lol.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •