MouseEvents and pop-up objects onClick …part 2

So I mentioned earlier that most of my website is going to have interactivity built around the user clicking the mouse. In an earlier post, I demonstrated how to make a MosueEvent with actionscript 3.0, and we tested it using the trace function.

Now, I want to actually have something appear on the screen. Tracing is great for letting me know what’s wrong or right, but not great for creating interactivity. In this tutorial, we will actually create a pop-up that appears after a click.

What I am going to do is use the yogurt, oatmeal, and toast as buttons to click on. I add my actions layer first and make sure that all my objects are symbols with instance names next. You can right click and convert to symbol. Here is what my stuff looks like once it’s in place:

So I am going to create actionscript that creates the “yumm” text any time you click anywhere on the oatmeal.

Now, to make the Oatmeal a button, first we need a little script. It looks like this:

“oatmeal” is the Inference name and buttonMode means that when you mouse over the item, the cursor will change to represent a click  functionality. This will be helpful so that users know where to click.

Next we need our famous eventListener. These are what tell the computer to not just look for a mouse over a button, but look for a mouse click. If you need a review of that, look back at my first post on MouseEvents.

Our event listener in this case is listening for a click ON our button Oatmeal.

After that, we have to actually add in our function. Remember, the function is what the script looks at to start when it has to run something.

At this point, the x and y signifies the position on the stage. You can use this to place the object. The “yumtext” is my abbreviation for the text I created that says, “Yummm.” It is what will appear when I click on the oatmeal.

Now test your flash file and see how it works! Remember, if you have issues, use the trace command to track them down.


~ by avanim on April 12, 2010.

%d bloggers like this: