Information Technology - Unit 2

IT Pathways: Outcome2

Coding Tasks

  1. Image Gallery 1 (Objects, Events, Methods)
    Scroll through images using a forward and back button
  2. Angry Bird Move 1 (Objects, Events, Properties, Variables)
    Move object in one direction on button press
  3. Angry Bird Move 2 (Objects, Events, Properties, Functions)
    Move an object up/down left/right and rotate on button press
  4. Angry Bird Game 1 (Objects, Method, Properties, Conditional Statement)
    Move an object up/down left/right on key press
  5. Angry Bird Game 2 – players - Hit test and score (As above + variables)
    As above and test if one object hits another, keep score
  6. Text input /output 1 – (Variables, Objects, Conditional Statement)
    Test a users text input and return a result
  7. Dress Up / Drag and drop (Objects, Methods, Events)
    Drag an object to different parts of the screen
  8. Sound Player – (Sound Methods, Objects and Events)
    Start playing music on a simple event (mouse press)
  9. Complex Sound Player (Sound Methods, Objects and Events)
    Create at complex sound player that controls, play/pause and volume slider
  10. Loops – (For loops or While loops)
    Create an interactive game that uses loops to give the user different feedback and tasks.

6. Text input /output 1 – (Variables, Objects)
Test a users text input and return a result

Objects

Enter Button = nameButton

Virgo = VirgoButton

Leo = LeoButton

Cancer = CancerButton

Events

When the enter button is released your name will be returned.

When the star sign button is released your prediction will appear

Variables
All text box variables.

Name input box variable = nameInput

Name output box variable = nameOutput

Horoscope output variable= Prediction

Code

stop();

// declaring variables

var nameInput:String = "";

var nameOutput:String = "";

var Prediction:String = "Select your star sign";

//name is returned when enter button pressed

nameButton.onRelease = function(){

nameOutput = nameInput;

};

//prediction for Virgo when Virgo button is pressed

VirgoButton.onRelease = function(){

Prediction = "Getting your finances in order and reeling in some new work becomes priority numero uno. If you lost touch with a dear friend over the past year, get back in contact with a heartfelt email.";

}

Task

Create predictions that will appear for the two other star signs when the buttons are released.

7. Dress Up / Drag and drop (Objects, Methods, Events)
Drag an object to different parts of the screen

Objects
Clothes all movie clips

T shirt = tshirt

Top =top

Pants = pants

Slacks = slacks

Events

instanceName.OnPress = function()

When the mouse is pressed on a clothing object something will happen. The object will move with the mouse.

instanceName.OnRelease = function()

When the mouse is released the object will stop moving.

Methods
this.startDrag();

Dragging an object with the mouse when an event is detected, egOnPress.

this.stopDrag();

Dragging an object with the mouse when an event is detected, egOnRelease.

Conditional Statements

if (this._x > 170 & this._x < 280 & this._y > 100 & this._y < 250)

{

this._x = 222;

this._y = 178;

}

If the movie being dragged is close to the target it will lock into the correct x and y position.

Code

This code allows the user to drag the tshirt and pants into position.

tshirt.onPress = function() {

this.startDrag();

};

tshirt.onRelease = function() {

this.stopDrag();

if (this._x > 170 & this._x < 340 & this._y > 30 & this._y < 200)

{

this._x = 228;

this._y = 70;

}

};

pants.onPress = function() {

this.startDrag();

}

pants.onRelease = function() {

this.stopDrag();

if (this._x > 170 & this._x < 280 & this._y > 100 & this._y < 250) {

this._x = 222;

this._y = 178;

}

};

Task

Create code to also allow the slacks and top to be dragged into the correct position.

8. Sound Player – (Sound Methods, Objects and Events)
Start playing music on a simple event (mouse release)

Objects
Play buttons

Happy by Parrell = playSongButton

Jamminbyt Bob Marley = playSongBobButton

Events

instanceName.OnRelease = function()

When the mouse is released on button song will start.

Methods
Assigning a variable to contain a new sound

Music = new Sound(this);

Attaching a sound to the variable

Music.attachSound("Happy");

Starting the sound

Music.start();

Code

Music = new Sound(this);

Music.attachSound("Happy");

Jammin = new Sound("this");

playSongButton.onRelease = function () {

Music.start();

}

//playSongBobButton.onRelease = function () {

Task

Complete the code to play the Bob Marley song when the button is released.

9. Complex Sound Player (Sound Methods, Objects and Events)
Create at complex sound player that controls, play/pause and volume slider

/ Start Position.
Three controls, Play/Pause and Stop Buttons with a volume slider.
/ Play
When the play button is pressed the sound starts.
The play button turns into a pause button.
The volume slider controls the sound level.
/ Loud
The volume slider set to high and the sound level is loud.
/ Pause
When the pause button is pressed the sound stops.
The pause turns into a play button.
The sound position is keep and the song will resume at that point when the play button is pressed.
/ Stop
When the stop button is pressed the sound stops.
The pause turns into a play button.
The sound position is set to 0 and the song will start at the beginning when the play button is pressed.

Objects
Play button = playBtn

Pause button = pauseBtn

Stop button = stopBtn

Volume slider (movie clip) = VolMC

Variables

var SongPosition:Number = 0;

This allows us to track how long the sound has been playing, initially set to 0.

var Volume:Number = 50;

This variable allows us to set and change the volume of a sound, initially set to 50.

Events

instanceName.OnPress = function()

When the mouse is press on button song will start, pause or stop.

Methods

Assigning a variable to contain a new sound

Music = new Sound(this);

Attaching a sound to the variable

Music.attachSound("jammin");

Starting the sound

Music.start(starting position, loops);

Setting the volume of the sound

Music.setVolume(Volume);

Properties

playBtn._visible = false;

pauseBtn._visible = true;

_visible controls if the object visible or not visible.

_visible = false; (object is not visible)

_visible = true; (object is visible)

PTO for code explanation and task

Code / Explanation
Music = new Sound(this);
Music.attachSound("jammin");
var SongPosition:Number = 0;
var Volume:Number = 50;
playBtn.onPress = function()
{
playBtn._visible = false;
pauseBtn._visible = true;
Music.start(SongPosition,99);
};
pauseBtn.onPress = function()
{
//add button visible code
SongPosition = Music.position / 1000;
Music.stop();
};
stopBtn.onPress = function()
{
// add
};
_root.onEnterFrame = function()
{
VolMC.onPress = function()
{
startDrag(this, false, this._x, 265, this._x, 70);
};
Volume = (195 - (VolMC._y - 70)) / 1.95;
Music.setVolume(Volume);
VolMC.onRelease = function()
{
stopDrag();
};
}; / A new sound variable is created and a Bob Marley song is attached to the variable.
Variables set the song position and volume is created.
When the play button is pressed, the follow happens
  • The play button disappears
  • The pause button appears
  • The song starts at according to the value of variable SongPosition and loops 99 times
When the pause button is pressed, the following happens
  • Variable SongPosition is set to the music position (in milliseconds) then divided by 1000 to give us seconds, eg 15 seconds.
  • Music stops.
When the play button is pressed, the following should happen
  • The play button appears
  • The pause button disappears
  • The SongPosition is set to 0
  • Music stops
Enter frame (a loop) is used to track the y position of slider.
When the mouse is press over slider it can move up or down
Variable Volume is set to according to y position of slide
Volume of song is set according to variable Volume
Drag stops when button released.

Your tasks.

Pause button: Add code to do the following

  • The play button appears
  • The pause button disappears

Stop button: Add code to do the following

  • The play button appears
  • The pause button disappears
  • The SongPosition is set to 0
  • Music stops

10. Loops – (For loops or While loops)
Create an interactive game that uses loops to give the user different feedback and tasks.

To be announce start of term 4.