A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] Needing help creating a simple door

  1. #1
    Junior Member
    Join Date
    May 2015
    Posts
    3

    resolved [RESOLVED] Needing help creating a simple door

    I'm extremely new to actionscript and still trying to learn, currently using as2.0 because i'm more familiar with it. I want to create a door where when a character walks in front of it and when a key is pressed it goes to another frame. I've been trying to look up tutorials and haven't found any at all. Anyone have a script that might help?

  2. #2
    Junior Member
    Join Date
    May 2015
    Posts
    3
    if (char.hitTestObject(door))
    {
    if (event.keyCode == Keyboard.SPACE)
    {
    gotoAndStop(2);
    }
    }

    Here's a script I've been trying to use. I'm not entirely sure if this is even correct.

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi,

    you're close to a solution with that code of yours. The only problem is that your code, if used by itself, will only check ONCE if char is touching/hitting the door, and that is when you first start your game. To continuously check for the character hitting the door, you can wrap your code in an enterFrame event, which basically runs repeatedly (code goes on a Frame):

    PHP Code:
    onEnterFrame = function(){
        if(
    char.hitTest(door)){
            if(
    Key.isDown(Key.SPACE)){
                
    gotoAndStop(2);
            }
        }

    The code is to be used on a Frame (you do this by selecting a frame and opening the actions panel), and it's assumed that you have the movieclips char and door on stage. If you want the door movieclip to go to Frame 2, then simply add this instead: door.gotoAndStop(2);

    also you're code seems to be in AS3, but I've converted it to AS2 above Let me know if you need help with understanding the code or even a sample FLA for testing
    Last edited by Nig 13; 06-04-2015 at 05:55 PM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  4. #4
    Junior Member
    Join Date
    May 2015
    Posts
    3
    oh wow! thanks, that helps a lot. I kinda suspected the code was AS3, I'm such a terrible noob XD

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Haha, no problem, glad I could be of help You're not a noob, anyone can make a mistake and we learn from our mistakes
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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