
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.
- Launch
Flash.
- Check
that the Main menu bar is open. If not:
- Select
Window > Toolbars.
- Select
Main.
- In
Layer 1 create a text object, with text “Pizza Toppings.”
- Name
the Layer “Objects.”
- Add
several Check Boxes by dragging them from the UI Components panel to the
stage.
- Click
on the first CheckBox and in the Properties panel
- Change
the Label to Pepperoni.
-
Change the Instance name to pepperoni.
- Repeat
for all other CheckBoxes.
- Select
all of the CheckBoxes and align them: Modify > Align.
- Select
“Left.”
- Select
“Distribute Heights.”
- Add
a button from the Common Button Library.
- Add
a text object that says “Make my pizza.”
-
Add the pizza.jpg image from d101student/ActionScript
2
- In
frame 80 insert a frame.
- Click
in frame 80 in the Objects layer.
- Select
Insert > Frame (or simply press F5.)
- Save
your file (in case you haven’t done that yet!).
Step 2: Insert Sounds.
- Record
your pizza toppings.
- Add a
new layer. Name it “Toppings.”
- Insert
a keyframe in frame 5.
- Drag
the sound that matches your first check box’s label to the stage.
- Click
in the keyframe and name the frame using the field in the Properties
panel.
- A few
frames after the sound is done, repeat 3 to 5 for the remaining
CheckBoxes.
- Repeat
until all sounds are installed in keyframes.
- Did
you save? Simple click the diskette icon in the menu bar.
Step 3: Add Actions.
- Add a
new layer. Name it “Actions.”
- 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.
- In
each frame before the sounds keyframes, insert a keyframe in the Actions
layer.
- Name
those keyframes, checkCheese, checkOlives, etc. In each case we will need
to check to see if we should play the sounds or not.
- Now
let’s get the action rolling:
- Select
the button.
- Access
Expert Mode in the Action Panel drop down menu
- Type
the following action in the action pane.
on (release) {
if
(Pepperoni.getValue() = = true) {
gotoAndPlay("pepperoni");
}
else
{
gotoAndPlay("checkCheese");
}
}
- Now
we need to decide if we are going to play the rest of the sounds.
- Select
the “checkCheese” keyframe.
- Type
the following action in the action pane.
if
(ExtraCheese.getValue() = = true) {
gotoAndPlay("cheese");
}
else
{
gotoAndPlay("checkOlives");
}
- 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.
|
- In
the last frame in the Actions layer, insert a keyframe. Add a stop action.
- Save
and test your movie.