• home
  • forum
  • my
  • kt
  • download
  • Attaching Blood through Actionscript

    Author: 2007-06-06 15:32:39 From:

    In this tutorial you will learn how to make a blood animation appear and play when you click. You can change the code a bit so the blood will appear when an enemy get hits or something. I am using Flash CS3, but Flash 8 and Flash MX 2004 will work as well.
    NOTE: If you are using Flash CS3, make sure you choose a AS 2.0 file.

    Click the box that says ¡®Export for Actionscript¡¯ and enter ¡®blood¡¯ into the identifier box.

    We can now attach the blood MC with actionscript. Enter this code onto the frame:

    Code (actionscript)
    1. var makeBlood:Object = new Object();
    2. var i:Number = 0;
    3. makeBlood.onMouseDown = function() {
    4.         attachMovie("blood","blood"+i,getNextHighestDepth());
    5.         setProperty("blood"+i, _x, _xmouse);
    6.         setProperty("blood"+i, _y, _ymouse);
    7.         i++
    8. };
    9. Mouse.addListener(makeBlood);

    Now if you test your movie (Ctrl+Enter) a the blood animation should appear when you click the mouse, but it won¡¯t disappear. We will fix that later, after I explain this code.

    Line 1: This is making a new object. This will be a mouse listener to check if the mouse button is pushed.
    Line 2: Just making a variable called ¡®i¡¯ that increases everytime the blood is made. This is so each blood MC has a different name. blood1, blood2 etc..
    Line 3: This is saying is the mouse button is down then to run the script between the curly braces.
    Line 4: Here the blood MC is attached to the stage using the ¡®attachMovie()¡¯ function. It is giving the MC an instance name of blood+i, so if blood is equal to 6 then its name will be blood6.
    Lines 5-7: This is making the blood MC¡¯s _x and _y coordinates equal to the mouses. Line 7 is increasing i by 1.
    Line 9: This is attaching the makeBlood listener to the mouse.

    Now double click on the blood MC in the library and select the last frame and enter this code. This will make the blood disappear.

    Code (actionscript)
    1. removeMovieClip(this);

    That just uses the removeMovieClip() function to remove the MC when it gets to that frame. If you test your movie you should get something like this.

    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