• home
  • forum
  • my
  • kt
  • download
  • Generate Walls through Actionscript

    Author: 2007-07-03 09:57:02 From:

    In this tutorial you will learn how to generate walls through actionscript. There height will change and you can make them go for as long as you want. I am using Flash 8 but Flash MX 2004 will work as well. This isn¡¯t the best way to do this, it is just the way I find easiest.

    Making the walls

    Now, open the library (Ctrl+L or Windows>Library) and you should see the MC you just made. Right Click on it and then go to ¡®Linkage¡­¡¯.

    Opening the Linkage Window

    A window labeled ¡®Linkage Properties¡¯ should now be open. Enter the same settings as I did below.

    Identifier: walls, Export for actionscript and first frame

    Now we can put our MC on the stage with actionscript by using the attachMovie() function. Enter this code onto the frame.

    If you tested your movie now (Ctrl+Enter) you would find that you would have the wall on your stage, and that it covers the whole stage length and changes heights. It doesn¡¯t move with the arrow keys yet, I will show you how to do that later. But for know I will explain the code you just got.

    Line 1: This is just declaring a variable called wallY. This is going to tell the wall what its _y coordinates should be.

    Line 2: This is creating an empty movie clip called holder. All the wall MC¡¯s that are placed on the stage will be held in here, so when it comes to moving them we can just move holder instead of having to use a for statement. This stops flash from lagging a bit.

    Line 3: This is where all the magic happens. It is a for statement, that will keep running until ¡®i¡¯ isn¡¯t less than 200. Therefore following code will 200 times.

    Lines 4-6: Here we are attaching the ¡®wall¡¯ MC to the stage. You should see that the code is holder.attachMovie(¡±wall¡­ That means we are attaching it inside the holder MC. We are also declaring the walls _x and _y coordinates. The _x coordinates is i*50, so basically it increases by 50 pixels each time. The _y is equal to the wallY variable.

    Lines 7-17: All of these lines are determining the walls height. 7-12 are seeing if the walls should move up or down. 12-17 are then making the wallY variable increase or decrease depending on what 7-12 came up with.

    Now, if you enter this code beneath the code I just gave you your walls should move with the arrow keys.

    That is pretty simple. The first line means ¡®Everytime this frame is entered¡¯. So the code after that will happen every frame. Unlike the previous you just got, which will only happen once.
    The rest of the frames are what makes the walls move. if(Key.isDown(Key.RIGHT)){ is an if statement that is checking is the right arrow key is pressed. If it is than the holder MC¡¯s _x coordinates is told to decrease by 5 pixels. That will make it move left, but appear as if you are traveling right. The next part says ¡®if the right arrow key isnt pressed, and the left one is make the holder MC move right¡¯.

    And that is it. You should now have something similar to this. (LINK)

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (66)
      Utilities (19)
      Getting Started (71)
      Video (10)
      Interactivity (21)
      Web Design (22)

    New

    Hot