Action Script 2 Lab: Components Action Scripting

At the end of this lab, you will have added interaction to a Flash movie using User Interface components: CheckBoxes.

Step 1: Create a Layer to work with.

  1. Launch Flash.
  2. Check that the Main menu bar is open. If not:
    1. Select Window > Toolbars.
    2. Select Main.
  3. In Layer 1 create a text object, with text “Pizza Toppings.”
  4. Name the Layer “Objects.”
  5. Add several Check Boxes by dragging them from the UI Components panel to the stage.
  6. Click on the first CheckBox and in the Properties panel
    1. Change the Label to Pepperoni.
    2. Change the Instance name to pepperoni.
  7. Repeat for all other CheckBoxes.
  8. Select all of the CheckBoxes and align them: Modify > Align.
    1. Select “Left.”
    2. Select “Distribute Heights.”
  9. Add a button from the Common Button Library.
  10. Add a text object that says “Make my pizza.”
  11. Add the pizza.jpg image from d101student/ActionScript 2
  1. In frame 80 insert a frame.
    1. Click in frame 80 in the Objects layer.
    2. Select Insert > Frame (or simply press F5.)   
  2. Save your file (in case you haven’t done that yet!).  

 

Step 2: Insert Sounds.

  1. Record your pizza toppings.
  2. Add a new layer. Name it “Toppings.”
  3. Insert a keyframe in frame 5.
  4. Drag the sound that matches your first check box’s label to the stage.
  5. Click in the keyframe and name the frame using the field in the Properties panel.
  6. A few frames after the sound is done, repeat 3 to 5 for the remaining CheckBoxes.
  7. Repeat until all sounds are installed in keyframes.
  8. Did you save? Simple click the diskette icon in the menu bar.

Step 3: Add Actions.

  1. Add a new layer. Name it “Actions.”
  2. In frame 1, add a Stop(); action. That provides a wait for the user to select the desired checkboxes and click the “Make my pizza.” button.
  3. In each frame before the sounds keyframes, insert a keyframe in the Actions layer.
  4. Name those keyframes, checkCheese, checkOlives, etc. In each case we will need to check to see if we should play the sounds or not.
  5. Now let’s get the action rolling:
    1. Select the button.
    2. Access Expert Mode in the Action Panel drop down menu
    1. Type the following action in the action pane.

on (release) {

            if (Pepperoni.getValue() = = true) {

                        gotoAndPlay("pepperoni");

            }

            else {

                        gotoAndPlay("checkCheese");

            }

}

  1. Now we need to decide if we are going to play the rest of the sounds.
    1. Select the “checkCheese” keyframe.
    2. Type the following action in the action pane.

            if (ExtraCheese.getValue() = = true) {

                        gotoAndPlay("cheese");

            }

            else {

                        gotoAndPlay("checkOlives");

            }

    1. Notice the pattern that emerges? If so, continue on to the last keyframe. If not, study the general form:  { and } are used a grouping symbols.

 

on (release) {   

                                               

            if (instanceName.getValue() = = true) {

                        gotoAndPlay("sound frame name");

            }

            else {

                        gotoAndPlay("next check frame");

            }

}

When the button is released on the mouse, begin

Check to see if the instance of the check box has been checked.

If so, go play the associated sound.

Otherwise,

Go see if the next sound should be played.

  1. In the last frame in the Actions layer, insert a keyframe. Add a stop action.
  2. Save and test your movie.