intro to action script 3

20
onic Visualization I : School of Art and Design : University of Illinois at Chicago Intro to Action Script 3 "The games of a people reveal a great deal about them.“ Marshall McLuhan

Upload: kyleigh-dallaher

Post on 13-Mar-2016

36 views

Category:

Documents


1 download

DESCRIPTION

"The games of a people reveal a great deal about them.“ Marshall McLuhan. Intro to Action Script 3. Review the random_answer.fla movie from the Pickup folder. Random function – random_answer.fla. The text buttons is a Dynamic Text linked to a variable “fortune”. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Intro to Action Script 3

"The games of a people reveal a great deal about them.“ Marshall McLuhan

Page 2: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – random_answer.fla

Review the random_answer.fla movie from the Pickup folder.

Page 3: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – random_answer.fla

The text buttons is a Dynamic Text linked to a variable “fortune”

Page 4: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – random_answer.fla

The invisible button contains all the scripts.

1. Array of the possible answers

on (release) {// make list of possible responsesresponses = new Array();responses.push("Yes");responses.push("No");responses.push("Ask again later");responses.push("It is certain");responses.push("Doubtful");responses.push("Probably");responses.push("The answer is unclear");responses.push("Of course not!");responses.push("Certainly!");responses.push("It looks positive");responses.push("It looks negative");

// get number of responsesn = responses.length;

// pick random responser = Int(Math.random()*n);

// place response in text areafortune = responses[r];

// start animationgotoAndPlay(2);

}

Page 5: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – random_answer.fla

The invisible button contains all the scripts.

1. Array of the possible answers

on (release) {// make list of possible responsesresponses = new Array();responses.push("Yes");responses.push("No");responses.push("Ask again later");responses.push("It is certain");responses.push("Doubtful");responses.push("Probably");responses.push("The answer is unclear");responses.push("Of course not!");responses.push("Certainly!");responses.push("It looks positive");responses.push("It looks negative");

// get number of responsesn = responses.length;

// pick random responser = Int(Math.random()*n);

// place response in text areafortune = responses[r];

// start animationgotoAndPlay(2);

}

Page 6: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – random_answer.fla

The array can also be a simple collection of variables:

on (release) {// make list of possible responses

responses = new Array("Yes", "No", "Ask again later", "It is certain",

"Doubtful", "Probably", "The answer is unclear",

"Of course not!", "Certainly!","It looks positive",

"It looks negative" );

Page 7: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – random_answer.fla

// get number of responsesn = responses.length;

// pick random responser = Int(Math.random()*n);

// place response in text areafortune = responses[r];

// start animationgotoAndPlay(2);

}

Page 8: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

Flash supports .aiff, .mp3, .wav, sound formats

Import sounds to the library

Page 9: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

Linkage

Identifier: song1

Export for ActionScript

Page 10: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

10 identical movie clips with dynamic text areas “song name” Named 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Page 11: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

10 identical movie clips with dynamic text areas “song name”Button script inside movie clip

on (release) {_root.playSong(this._name);

}

Page 12: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

10 identical movie clips with dynamic text areas “song name”Button script inside movie clip

on (release) {_root.playSong(this._name);

}

Takes the name of the movie clip – “1” to “10” –And sends it to a “playSong” function at the root level.

Used for each movie clip since the name is different each time

This._name gets different results from different instances of the same movie clip as long as they named differently

Page 13: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

dynamic text areas “song name” linked to variable “text”stop action on the first frame

Page 14: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

Page 15: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

Page 16: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

The text for each movie clip instance is changedEach instance displays a different song nameEven though we have one movie clip symbol in the library each

instance looks different on the stage

// set the song namesthis["1"].text = "Song Name 1";this["2"].text = "Song Name 2";this["3"].text = "Song Name 3";this["4"].text = "Song Name 4";this["5"].text = "Song Name 5";this["6"].text = "Song Name 6";this["7"].text = "Song Name 7";this["8"].text = "Song Name 8";this["9"].text = "Song Name 9";this["10"].text = "Song Name 10";stop();

Page 17: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

// play new sound

song = new Sound(); creates a sound object

song.attachSound("song"+songnum); associates the sound in the library with this object

song.start(); plays sound

Page 18: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Random function – jukebox.fla

function playSong(songnum) {// stop the previous song, if anysong.stop();

// turn off all lightsfor(i=1;i<=10;i++) {

this[i].gotoAndStop(1);}

// play new soundsong = new Sound();song.attachSound("song"+songnum);song.start();

// turn light onthis[songnum].gotoAndStop(2);

}

// set the song namesthis["1"].text = "Song Name 1";this["2"].text = "Song Name 2";this["3"].text = "Song Name 3";this["4"].text = "Song Name 4";this["5"].text = "Song Name 5";this["6"].text = "Song Name 6";this["7"].text = "Song Name 7";this["8"].text = "Song Name 8";this["9"].text = "Song Name 9";this["10"].text = "Song Name 10";stop();

Page 19: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Exercise – dice

Create an interactive animation dice game with two dice and button “roll” to through them.

Each dice has to display random number from 1 to 6 each time the button “roll” is clicked.

If both dice show the same number, change the color property of each dice and play a song.

Play randomly selected songs each time dice show the same number.

Change each dice color on each roll.

Play different song for each roll.

Page 20: Intro to Action Script 3

AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007

Exercise – dice

myObjectColor = new Color(“movieclip_name") ;

myObjectColor . setRGB (0 x FFFFFF ) ;