A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Help guys I need a good solution for this.

  1. #1
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Howdy,
    Here is what I need.
    Once a key is pressed to disable it. How do yo do this ? Here is the event. I have a guy which I move with the navigation keys. Once you press a key the guy moves one sptep but if you hold it down he will continue running. Since the guy moves preaty fast my collicion detection is going down.No time for the script to disable the movemt. I dont need this I need the key to be released and pressed again or no effect if you hold it down for a longer period. One step at a time.
    this is what I did with no avail:
    1. I used a time delay. so even if the key pressed and you hold it down the guy moves slow. I did not like. It was very criple movement.
    2. I used a flag variable embeded in the brick walls to disable the key pressed variable. Still no avail. the guy moves too fast no collision is happening.
    Im stuck. And this is the only bug, belive it or not wich holds back my tut for the next Maze thing.
    Hey tnx a lot.
    Mad_sci

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Why not on key press use a temporay variable that determines whether the man is already moving or not. ie

    On (Key: <Left>)
    If (/:move ne "1")
    Begin Tell Target ("yourmanmovie")
    Go to and Stop (the strat of your man moving)
    End Tell Target
    End If
    End Onthen inside your manmovie have at the end of the code or whatever set varaible: "/:move" = "0"
    basically thsi will only allow the kep to be pressed once,therefore only activate the movement once.and once the movement is over it allows for another movement!!!


    Hope that gives you some ideas!!!
    Regards FlashGuru

    p.s what is it you are working on???

  3. #3
    Member
    Join Date
    Jul 2000
    Posts
    81
    Also, on <keypress> you could send the <movieclip> to a new frame that doesnt have that <keypress> action available.

    I avoid actionscript though whenever possible, so I'm not sure if this is the same solution or not, but in a more fundamental form.

  4. #4
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Yes spang that may work too!!try them out mad-sci if none of them work then ill try and find another solution!!!

  5. #5
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hey guys tnx a million, Ill give em a shot tonight and let you know. I think we have to do a small tut if those experiments are fuitfull. It will be realy usefull to know how to disable a pressed key.
    Mad_sci

  6. #6
    Senior Member
    Join Date
    May 2000
    Posts
    107
    MadSci!
    How are you mate!
    I've been wrecking my brain for a soluton to your problem and this is the best one I've come up with so far...it's not good...the movement of the caracter isn't smooth,but the basic idea that if you hold down the key the guy stops and you have to press again for him to move is working...

    inside your caracterMC make four buttons (move_down)(move_up) etc....

    the MC has three frames with these buttons in each frame.

    in the first frame:actions=stop

    frame1 asign this action to the move_down button:
    ________________________
    On (Release, Key: <Down>)
    Set Property ("/down", Y Position) = GetProperty ("/down",_y)+5
    Set Variable: "x_value" = GetProperty ("/down",_x)
    Set Variable: "y_value" = GetProperty ("/down",_y)
    Go to and Play (2)
    End On
    _________________________

    frame3 asign this action to the move_down button:
    ___________________________
    On (Release, Key: <Down>)
    Go to and Play (2)
    End On
    __________________________

    and of cource the same for the move_up button etc...

    I tried it and it works...(but as I said...it's ugly)
    maybe you can modify it so that it works smoother...

    good luck!

    lemme know how your doing...you can mail me if you want the .fla or any questions or anything...

    (sory folks for the looong post:P)


  7. #7
    Senior Member
    Join Date
    May 2000
    Posts
    107
    what the h*** is the smileys doing in the code examples...how did they get there?????...he he he...

    sorry bout that.......

  8. #8
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hey IOR im cool man tnx for the code Ill try that as well. I do it other way arroud i have 4 mc one for each direction and I use one button to control them actualy to pass variable to the time line and according to that variable I use visibility on/off to swich on or off the appropirate move for that direction. The problem was the movement when the key is held down. Here is what Im planning to do:
    since in that movie I have 3 frames
    layer 1. 3keyframes
    1. init the static variables.
    2. the actual AS
    3. goto play 2
    in the layer 2. 1 keyframe 2 frames. I have the nested mc+ the button. but i have frames only now if I make the frames key frames I can paste the button in the middle keyframe only.

    Hypothesis:

    the key is pressed and held down. A variable is sent to the time line and a key of events are happening. the variable goes to 0 the movie goes to next frame where there is no button which will eliminate the key pressed stuff and since the variable is 0 no movement will occur till you relese the button and press it again. cool a ? Were was my brain yestarday ?
    Mad_sci

  9. #9
    Senior Member
    Join Date
    May 2000
    Posts
    107
    I think we're thinking in the same direction only our methods are a bit diffrent...

    my way of doing it was based on the idea that in the first of the three frames you place the script that moves the MC etc...(on key press <Down>)and goes to frame two... in frame two and three the movie loops if you continue to hold down the key and only if you release the key the movie comes out of the loop and goes to frame one again ...where the script that moves the MC down is...and you can press it again

    I've never used the "loop" action but maybe you can use that instead of a "manual" loop?

    placing something like "loop while pressing the down key" in frame two?

  10. #10
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    Ior disable smilies in your post if you do post some actionscript.

  11. #11
    Senior Member
    Join Date
    May 2000
    Posts
    107
    ok jdynas..thanx!

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