Coding is done primarily through functions and event listeners.
import flash.events.KeyboardEvent;
//when a key is pressed go to scene for decision.
function keyPressed(event:KeyboardEvent):void
{
gotoAndPlay (50);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stop();
function nice(event:MouseEvent): void
{
gotoAndPlay (75);
}
function hungry(event:MouseEvent): void
{
gotoAndPlay (85);
}
button1.addEventListener(MouseEvent.MOUSE_DOWN, nice);
button2.addEventListener(MouseEvent.MOUSE_DOWN, hungry);
stop();
Code that did not work for me:
//
////the user clicks the fork, so create a function to take them to the scene where the man is crushed by sumo
//function hungry(event:MouseEvent):void
// {
// gotoAndPlay (75);
// }
//
////the user gives the pig a book so take them tot he scene where the two fall in love
//function nice(event:MouseEvent):void
// {
// gotoAndPlay (85);
// }
//
////add listeners for the functions above
//book.addEventListener(MouseEvent.MOUSE_DOWN, hungry);
//fork.addEventListener(MouseEvent.MOUSE_UP, nice);
//stop();
and
//
//function nice(event:MouseEvent): void
//{
// gotoAndPlay (75);
//}
//
//
//function hungry(event:MouseEvent): void
//{
// gotoAndPlay (85);
//}
//
//button1.addEventListener(MouseEvent.MOUSE_DOWN, nice);
//button2.addEventListener(MouseEvent.MOUSE_DOWN, hungry);
//stop();
and
//
//import flash.events.MouseEvent;
//
////make the pig get bigger when he is clicked
//function onPig(e:MouseEvent):void
//{
// pig.scaleX = 1.4;
// pig.scaleY =1.4;
//}
////make the pig go back to normal when he is clicked
//function offPig(e:MouseEvent):void
//{
// pig.scaleX = 1.0;
// pig.scaleY =1.0;
//}
//
//// attach listeners to event sources
//button.addEventListener(MouseEvent.MOUSE_DOWN, onPig);
//button.addEventListener(MouseEvent.MOUSE_UP, offPig);
//