MouseEvents Part 3.

My biggest use of Flash and Actionscript is going to be the gotoAndPlay command. I’ll also be using gotoAndStop, which is very similar, except without animation. Here’s how I’m using it.

Earlier, I posted how to use MouseEvents to determine when the mouse is clicked, with a trace command attached. In Part 2, I showed how to use the MouseEvent to make something appear. My final post is what most of my flash project is revolving around, so I think it’s a fitting end.

We all remember my silly oatmeal and my yogurt. Now I’ve made a start screen and I have a button for the viewer to click. It will take them through a series of choices. So for instance, I need my “go” button on my first page to take my viewer to the next scene.

Here is my go button:

My button’s instance name is gobuttonn1.

I open my actions layer in my flash project on the same keyframes as the go button is visible. Then, I write this code:

Now, in previous posts, I discussed mouse events and how you can create a function for each. The mouse event here is the same: it’s an event listener, and it’s looking for MOUSE_DOWN, or when someone clicks the mouse. The new part is this:

gotoAndPlay (83);

In this case, gotoAndPlay is the action in the function we set up (called onClick). That means that when we click the button, it will run the function that says, “Go to keyframe 83.” Keyframe 83, in this case, is the place where my bowl of oatmeal and yogurt come in. So it take me instantly to there, and then the action starts!

As an end note, I haven’t decided if I want to have static scenes, or animated ones. Animated seems more fun, but it requires that I leave enough keyframes between “scenes” to have the action play out. If I go this route, I’ll be using the gotoAndPlay command.

I also could have static pages with no animation. This would drastically shorten the amount of keyframes I have, and it would make finding things in the timeline a whole lot easier and cleaner. In that case, I’d use gotoAndStop. It does limit what I can do with animation, which is a choice I guess I’ll have to make…



~ by avanim on April 17, 2010.

%d bloggers like this: