A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: action scripting not work for loop play?

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Posts
    13

    action scripting not work for loop play?

    well, here's the action script i'm trying to get...

    this.onEnterFrame = function(){
    if(Key.isDown(Key.RIGHT)){
    gotoAndPlay("5");
    };
    }

    *cough*indogo thanks alot...like coffee*cough*

    i have kool moves 5.2.3 and i'm trying to get it when you press right, it goes to the "icon"

    problem is though, i have a loop play on frame 3 and when i press right, it goes straight to frame 1. I think it's cuz of the loop play.

    if any 1 has any advise plz post

  2. #2
    Banned XareoX's Avatar
    Join Date
    Aug 2006
    Posts
    462
    Ok so you press left button and it doesnt loop try this post that code in and then go to frame 5 then go to the actionscript/sounds window then press the + button then click the button that says ''go to frame'' then change those drop down menus so it says ''keyframe 1'' and ''play'' that should make it loop.

  3. #3
    Junior Member
    Join Date
    Aug 2006
    Posts
    13
    no, i already know how to loop

    i want an action script to go to key frame 4. This won't work though

    I also have key frames 1-3 and three goes to key frame 1 on loop

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by ksouth
    well, here's the action script i'm trying to get...

    this.onEnterFrame = function(){
    if(Key.isDown(Key.RIGHT)){
    gotoAndPlay("5");
    };
    }
    You're not trying to use this in the main timeline are you? Because the onEnterFrame will only work on a child movie within the main timeline. Use a dummy movie clip with your repeated actions like this in it. or use setInterval to have the function keep checking.

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    If the frame you go to is the last one, try gotoAndStop instead of gotoAndPlay. You might have forgotten to set a stop action at the end of your movie.
    Last edited by w.brants; 08-17-2006 at 02:40 PM.

  6. #6
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Hi there.....sorry didn't get back sooner..

    Examine the attached file...left arrow goes to frame 3...right to frame 5...I presume you are needing multiple actions..

    note...the keyframes have been named (as mentioned before)(rightclick/rename in movie explorer or timeline)..jumping is unpredictable otherwise and causes the effect you describe.

    I had to add a dummy frame at the end which was needed for stability (aka stopping in the first keyframe is not reliable)...the flash player does have the odd quirk..

    The code does work in the main timeline (even though it shouldn't) but I was going to suggest creating a movieclip for handling your keyboard actions (in a similar way that buttons are types of movieclips)...so actions would become _root.gotoAndPlay("three"); and so on...note the movieclip would need to be present in all main timeline frames.

    Ok hope you get there

    mike
    Attached Files Attached Files

  7. #7
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Instead of onEnterFrame you could also use a key listener.
    That probably requires less cpu load because it is only triggered when a key is pressed and doesn't have to perform actionscript code each enterFrame event.

  8. #8
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Instead of onEnterFrame you could also use a key listener.
    That probably requires less cpu load because it is only triggered when a key is pressed and doesn't have to perform actionscript code each enterFrame event.
    Yes that sounds better...the method I used was the only one I could find when I was looking some time ago....macromedia incorporate key detection into the button action so I needed the equivelent method for koolmoves.

    I remember trying a key listener without success...do you have an example of working syntax?

    regards

    mike

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Code:
    listener = new Object();
    
    listener.onKeyDown = function () {
    
     var keycode = Key.getCode();
    
     if (keycode == Key.LEFT){
    
      _root.txt1.text = "You pressed LEFT";
    
     } else if (keycode == Key.RIGHT){
    
      _root.txt1.text = "You pressed RIGHT";
    
     }
    
    }
    
    Key.addListener(listener);

  10. #10
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Thankyou for that...I'm off to play with it myself (perhaps I should rephrase that!)

    regards

    mike

    edit...well I'm pleased to report that it worked a treat...perfect response which is independant of frame rate (does a small celebration dance) definately a better method...ow where did ksands go
    note...I used it in the main timeline.
    Last edited by indogo; 08-18-2006 at 10:51 AM.

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