A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Action Script Question

  1. #1
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    Action Script Question

    I created a maze game where you have to guide your ball to the exit.
    I have all the action script for the walls and such, but not for the controls.
    Im looking for an action script where if your left,right,up, or down key is
    pushed, you move left right up or down according to what button you pushed.

    Thanks,
    -------Mystikal

  2. #2
    Some dude, says hi Ultra Pulse's Avatar
    Join Date
    Jun 2005
    Posts
    262
    UPDATE: you might have to press on the screen for the code to work.


    All tested and ready to go, if you want it faster or slower change the speed value higher or lower. Also pay attention to the comment line after "//"

    onclipEvent(load){
    speed = 5 //change this number to make the object move faster
    }
    onClipEvent(keydown){
    if (key.isDown(key.DOWN)){
    _y += speed
    }
    }
    onClipEvent(keydown){
    if (key.isDown(key.UP)){
    _y -= speed;
    }
    }
    onClipEvent(keydown){
    if (key.isDown(key.RIGHT)){
    _x += speed;
    }
    }
    onClipEvent(keydown){
    if (key.isDown(key.LEFT)){
    _x -= speed;
    }
    }
    Last edited by Ultra Pulse; 09-02-2005 at 12:55 PM. Reason: UPDATE on making it work

  3. #3
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    Thanks

    Why thank you ultra pulse.
    Works fine.

    -Mystikal

    Edit: I showed my friend the game
    and he suggested something.
    When you push the left key, it
    shows the left side of the object.
    So say you had a sprite and you
    hit the left arrow key, it would
    show him looking to the left.
    Any one know what i can do?


    If you can help thanks
    -Mystikal
    Last edited by -Mystikal; 09-02-2005 at 01:06 PM. Reason: Another question -.-

  4. #4
    Some dude, says hi Ultra Pulse's Avatar
    Join Date
    Jun 2005
    Posts
    262
    If you're going to be using the flash 7 plugin, I didn't capitalize certain things, and it might not work.

  5. #5
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    I see

    Ah i see that might pose a problem
    for people without it
    Last edited by -Mystikal; 09-02-2005 at 01:07 PM. Reason: BLAH

  6. #6
    Some dude, says hi Ultra Pulse's Avatar
    Join Date
    Jun 2005
    Posts
    262
    Quote Originally Posted by -Mystikal
    Why thank you ultra pulse.
    Works fine.

    -Mystikal

    Edit: I showed my friend the game
    and he suggested something.
    When you push the left key, it
    shows the left side of the object.
    So say you had a sprite and you
    hit the left arrow key, it would
    show him looking to the left.
    Any one know what i can do?


    If you can help thanks
    -Mystikal
    Yes, I can fix it, But it'll take a few minutes so hold on a sec.

  7. #7
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    :d

    Sweet

  8. #8
    Some dude, says hi Ultra Pulse's Avatar
    Join Date
    Jun 2005
    Posts
    262
    Sorry, I was getting the correct degrees to turn, I finally found an image on google, hope this is what you want, also if you don't need something tell me.

    oh crud, the guy turns facing the way, I'll just edit it when it's ready again.
    this only works for an overhead view...

    Code:
    onclipEvent(load){
    speed = 5 //change this number to make the object move faster
    }
    onClipEvent(keydown){
    if (key.isDown(key.DOWN)){
    this.rotation = 0;
    this._rotation = 180;
    _y += speed;
    }
    }
    
    onClipEvent(keydown){
    if (key.isDown(key.UP)){
    this.rotation = 0;
    this._rotation = 0;
    _y -= speed;
    }
    }
    onClipEvent(keydown){
    if (key.isDown(key.RIGHT)){
    this.rotation = 0;
    this._rotation = 90;
    _x += speed;
    }
    }
    onClipEvent(keydown){
    if (key.isDown(key.LEFT)){
    this.rotation = 0;
    this._rotation = 270;
    _x -= speed;
    }
    }
    Last edited by Ultra Pulse; 09-02-2005 at 01:35 PM. Reason: Forgot code

  9. #9
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    Sweet

    Ya it works, i see what you meen by overhead.
    Mabye it would work if when you pressed the button,
    it changed the pic so that its facing the other way.
    But, this will do fine for now.

    -Mystikal

  10. #10
    Some dude, says hi Ultra Pulse's Avatar
    Join Date
    Jun 2005
    Posts
    262
    Correct, all you have to do is make 4 frames on the MC. put stop commands on all of them, instead of the "this._rotation = somenumber" you put "gotoAndStop ("framename"), if you give me your FUN file, I'll gladly do it, except you have to draw his back.

  11. #11
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    yay

    No need i already did it. LOL

    Thanks for all the help.

    -Mystikal

  12. #12
    Member
    Join Date
    Aug 2005
    Location
    Canada, Ontario.
    Posts
    42

    One more...

    Just one more question,
    the pic im importing is a .png
    but i want to know how to make
    it transparent.

    thanks for ALL the help

    -Mystikal

  13. #13
    Some dude, says hi Ultra Pulse's Avatar
    Join Date
    Jun 2005
    Posts
    262
    I think you goto the fill tool, and the fourth option is the transperancy option. set it from 0-100.

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