Unit 10 - ActionScript Intro

Working with ActionScript

 

Homework

For this homework you will create 3 version of interactive Flash files and then put them into a folder, zip that folder and turn that in..

Homework Part 1

Create a button the performs a trace function and outputs a string of text to the output window. See example below but make sure you write your own code from scratch and use your own unique function and instance names.

stop();

trace_btn.addEventListener(MouseEvent.CLICK, traceFunction);

function traceFunction(event:MouseEvent) {
trace("the button is working");
}

Homework Part 2

Create a file that contains at least 3 pages and 3 buttons using addEventListener for each button that calls its own unique function.
See example below but make sure you write your own code from scratch and use your own unique function, label and instance names.

stop();

home_btn.addEventListener(MouseEvent.CLICK, gotoHome);

function gotoHome(event:MouseEvent):void {
gotoAndStop("home");
}

page1_btn.addEventListener(MouseEvent.CLICK, gotopage1);

function gotopage1(event:MouseEvent):void {
gotoAndStop("page1");
}

page2_btn.addEventListener(MouseEvent.CLICK, gotopage2);

function gotopage2(event:MouseEvent):void {
gotoAndStop("page2");
}

Homework Part 3

Take homework 2 to the next level by having all the buttons call the same function and have that function get the name of the button (which will be the same as the frame label) and navigate the the correct frame. See example below but make sure you write your own code from scratch and use your own unique function, label and instance names.

stop();

home_btn.addEventListener(MouseEvent.CLICK, navigate);
page1_btn.addEventListener(MouseEvent.CLICK, navigate);
page2_btn.addEventListener(MouseEvent.CLICK, navigate);

function navigate(event:MouseEvent):void {
gotoAndStop(event.target.name);
}