This example shows how to listen for various mouse events, and just as important, it shows how to load items from the library for this Flash file onto the stage.
Download the FLA fileThe main timeline has two frames. Frame 1 contains a 'Start' button, and frame two contains the real action. Here's the code for frame 1:
stop();
startButton_btn.addEventListener(MouseEvent.CLICK, myGotoNextFrameFunction);
function myGotoNextFrameFunction(myMouseEvent:MouseEvent)
{
nextFrame();
}
Below is the code for frame 2.
stage.addEventListener(MouseEvent.MOUSE_MOVE, myMouseMoveFunction);
stage.addEventListener(MouseEvent.CLICK, myMouseClickFunction);
// The mouse wheel functionality may not work on the Mac.
// For mouse wheel prompt to appear, click on the stage first. Adding a 'start' button
// would achieve this.
stage.addEventListener(MouseEvent.MOUSE_WHEEL, myMouseWheelFunction);
function myMouseMoveFunction(myMouseEvent:MouseEvent):void
{
var myMove_mc:myMove = new myMove();
addChild(myMove_mc);
myMove_mc.x = 100;
myMove_mc.y = 90;
}
function myMouseClickFunction(myMouseEvent:MouseEvent):void
{
// add library movie clip myClick to the stage, and name the new instance myClick_mc.
// for this to work, note that we had to check the box for 'Export for ActionScript'
var myClick_mc:myClick = new myClick();
addChild(myClick_mc);
myClick_mc.x = 100;
myClick_mc.y = 110;
}
function myMouseWheelFunction(myMouseEvent:MouseEvent):void
{
var myWheel_mc:myWheel = new myWheel();
addChild(myWheel_mc);
myWheel_mc.x = 100;
myWheel_mc.y = 130;
}
stop();