A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Why does this cause it to skip?

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Posts
    394

    Why does this cause it to skip?

    I have this actionscript that works fine until you try and move your mouse

    once you move it, the frame skips back to the beginning

    why??

    Code:
    onClipEvent (enterFrame) {
    	stop();
    }
    
    on (keyPress "<Space>") {
    	play();
    }

  2. #2

  3. #3
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    I can't, if I do then it will the movie will play...and I don't want that until you press the space bar via the 2nd part of the code

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Yes you can, it should only be a stop(); in the FRAME not on the movieclip or button or whatever your using.

  5. #5
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    didn't work it just plays it, no stopping action

  6. #6
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    change it to:

    Code:
    onClipEvent(load){
    this.stop();
    }

  7. #7
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    great but how come when I hit spacebar, play, it just jumps back to the beginning

  8. #8
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    and when I move my mouse it jumps back to the beginning

  9. #9
    Dukenuke Productions
    Join Date
    Oct 2005
    Location
    Over here
    Posts
    15
    Try this instead:
    Code:
    if (Key.isDown(Key.SPACE)) {
    	play();
    }

  10. #10
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    There's no correlation between mouse movement and playback (unless of course you are specifically using a mouse listener to control playback for some reason)

    onClipEvent() commands must be placed directly on a movie clip.

    So we are assuming you have a movie clip on stage with the code you provided.

    //load commands fire once and only once when the clip appears for the first time
    onClipEvent('load'){
    }

    //enterFrame commands fire every frame according to your movies framerate
    onClipEvent('enterFrame'){
    }

    By putting a stop() in there you are forcing the timeline to stop immediately and it wont start playing again until space is pressed.

    Btw, on() and onClipEvent() are barely used anymore. All code is put on the timeline now.
    Read here for more
    http://www.kirupa.com/developer/mx/movement_keys.htm

  11. #11
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    so why does it jump?

  12. #12
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    ok so I have this actionscript on my movie clip on the first frame of the movie
    Code:
    onClipEvent(load){
    this.stop();
    }
    on (keyPress "<Space>") {
    	play();
    }
    but when I try to copy and paste the frames, it doesn't stop it just keeps going. Even with the stop on the movie actionscript and the frame...how can I get this to work. My overall objective is to have a video that plays when you hit space and has to loop 12 times before continuing but, you have to hit space to start the loop

  13. #13
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Quote Originally Posted by kraxyk
    My overall objective is to have a video that plays when you hit space and has to loop 12 times before continuing but, you have to hit space to start the loop
    Heh, that should have been your first post.

    Start a new flash file. Then create a new layer and name it actions.
    on frame 1 of actions place this code.

    PHP Code:
    stop();
    var 
    timesPlayed:Number 0;
    keyboardListener = new Object();
    keyboardListener.onKeyDown = function(){
      if(
    Key.SPACE == Key.getCode()){
        
    play();
      }
    }
    Key.addListener(keyboardListener); 
    Then, select the last frame of the video on the actions layer, hit F7 (add empty key frame) and add this.
    PHP Code:
    if(timesPlayed 12){
      
    gotoAndPlay(2);
      
    timesPlayed++;
    }else{
      
    stop(); //or whatever command for after it's played 12 times


  14. #14
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    it didn't work

    it just keeps repeating
    Last edited by kraxyk; 05-04-2008 at 09:16 PM.

  15. #15
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Then there is something different about your .fla than the setup I described.
    This is assuming you ditched all the other code and placed mine on the root timeline, NOT a movieclip.

  16. #16
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    I did what you said, but just to let you know I have the default layer, a layer I created then the layer you told me to create, and also my video is on frame 97-109, and there is no actionscript on the movie of on the first frame
    Last edited by kraxyk; 05-06-2008 at 03:31 PM.

  17. #17
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I would say post your files somewhere for us to look at. Your not doing something right because everything he has suggested should work without a problem.

  18. #18
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Ok last shot, if not you're gonna have to hit the books.

    Delete any actions I've given you so far and just put this on frame 1

    PHP Code:
    stop();
    var 
    startFrame:Number 97;
    var 
    endFrame:Number 109;
    var 
    timesPlayed:Number 0;
    keyboardListener = new Object();
    keyboardListener.onKeyDown = function(){
      if(
    Key.SPACE == Key.getCode()){
        
    startLooping();
      }
    }
    Key.addListener(keyboardListener);

    function 
    startLooping(){
      
    gotoAndPlay(startFrame);
      
    onEnterFrame = function(){
        if(
    _currentframe >= endFrame){
          if(
    timesPlayed 12){
            
    gotoAndPlay(startFrame);
            
    timesPlayed++;
          }else{
            
    gotoAndStop(endFrame);
            
    delete onEnterFrame;
          } 
        }
      }


  19. #19
    Senior Member
    Join Date
    Jan 2008
    Posts
    394
    frame one of the whole flash file or just the movie?
    and on which layer. Actions, default, or the other extra one

  20. #20
    Member
    Join Date
    Aug 2006
    Location
    Philadelphia, PA
    Posts
    58
    Probably he means frame 1 of the whole flash file, on the actions layer (ALWAYS use an actions layer for your actions.)

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