Interactive Authoring
Week 2
- Your mid-term project is to create 2 games; one will be based on the games that we examine in class and the other will be an original creation. Your original creation should be very simple but really well done.
- Both game projects will use your original artwork, employ some modification to the game play, and use sound effects.
- During class on week 5, you will demonstrate and present your games to the class. Be prepared to explain the changes to the games and explain your code line-by-line.
- This week we will expand our knowledge and experience with ActionScript as follows:
- Using AS with buttons (pg98 Expanding Buttons in the text book)
- Ideas for designing and programming your own menus and buttons
- Review of what we have learned so far
- Cool Flash game web sites:
- neopets.com
- miniclip.com
- mousebreaker.com
- flasharcade.com
ActionScript Techniques
Text Fields
- To display text that will not change, like for instructions, create a text field and set the property to Static Text.
- To collect information from the user, set the property to Input Text.
- To display data that you will change using ActionScript, set the property to Dynamic Text. If you create a variable in AS that will contain the text that you want to display in the field, set the var field on the property bar to the var you use in your code and the display will update automatically.
- In the following Flash movie there are all three types of text fields. The action code belongs on the button and looks like this:
on(release){
input=_root.inputField.text;
}
Frame Labels
- When you add an Instance reference to a frame you can refer to it by name as opposed to number. This is handy because you can make changes to the timeline without changing the code. Your reference would be
- gotoAndPlay(“part1”); instead of….
- gotoAndPlay(15);
- When you click a button:
on(press) {
gotoAndStop(“part1”);
}
Movie Clips
- Remember to give each instance of a movie clip on the stage an instance name. You can not refer to the movie clip's name in the Library because you may have more than once instance on the stage at a time. The instance name field is on the lower right corner of the Property bar.
- When you want to control a movie clip based on a frame event:
onClipEvent(enterframe) {
this._x--;
}
“this” is used when a movie clip refers to itself.
_x is the horizontal position
_y is the vertical position
-- decrements a variable, in this case to the left or down
++ increments a variable, in this case to the right or up
For example, to move a movie clip 5 pixels to the left:
-
this._x -=5;
Variables
- Variables hold data. For example: myVariable = 5;
- Increment the contents of a variable (by 2 in this case) with myVariable+=2;
- Evaluate the contents of a variable with == as in the following:
If (a==7) {gotoAndPlay(“explode”);
} - Control playback of movie clip
On(press) {myMovieClip.stop();
}Or use
.gotoAndPlay
or
.gotoAndStop
or
.prevFrame
or
.nextFrame - Scale a Movie clip
Fox._xscale = 50;
- Rotate a movie clip
Fox._rotation = 30;
- Make a movie clip position equal to the mouse position
onClipEvent (enterFrame) {
if (drag) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
}
Note that _root refers to the main timeline.
- Attach a movie clip on the main timeline
_root.attachMovie(“movieName”,”instance name”, “layer”)
- The Movie Name is the name entered in the Identifier field in the Linkage Properties dialog box. To set this, right mouse click (RMC) on the movie in the Library.
- Also use this construction for
- DuplicateMovieClip
- RemoveMovieClip
Loops
- To Create Multiple instances of a movie clip
OnClipEvent(load) {
//create 10 movie clips
For(i=0;i<10;i++) {
_root.attachMovie(“sample”,”sample”+I,i);
//set the position
_root[“sample”+i]._x = i*37;
_root[“sample”+i]_y=100;
}
}
With the above to loop through every other movie clip set the final i to +=2 and it will jump by 2.
Detect a collision
If(_root[“target”].hitTest(_root[bullet”])) {
Do something here
}
Else
_root[“bullet”]._x -=5;
}
Detect a keypress
on (keyPress “r”) {
gotoAndPlay(1);
}
The keypress detection is case sensitive; r is different from R
For game play you might want to use this:
OnClipEvent(enterframe) {
If (Key.isdown(Key.RIGHT)) {
_root.circle._x++;
}
See page 81 in the text book to understand the limitations and advantages of each technique.
Play a sound
On (press) {
mySound = NewSound();
mySound.attachSound(“beep”);
mySound.start();
}
Remember you have to RMC on the sound file in the Library and give it a linkage name.
- For sound, you can also control:
- mySound.setVolume (50);
- 0 is off and 100 is loudest
- mySound.setPan(-100);
- 0 in center, -100 is far left and +100 is far right
- Remember that once you set pan or volume it stays set until you reset it.
Math.random()
- Returns a floating point number between 0.0 and 1.0
- Multiply the result by the upper limit you want
- Math.random()*300 gives a number between 0 and 299…BUT there could be a result of 150.5
- Use the int function to round the result down to the nearest whole number
- N=int(math.random()*500; give a number between 0 and 499
Array
- Create
- Responses=new Array();
- Add
- Responses.push(“Yes”);
- Delete
- Responses.splice
- Display
- Make a Dynamic text box and link it to a variable. This example assigns item 3 to the var in the text box.
- fortune = responses[3]
- Total number of entries
- Responses.length
- Chose a random entry in the array
N = responses.length;
R = Int(math.random()*n);
Fortune = responses[r];