On September 29th I started working on an Actionscript 3.0 "Movement" program. The link to the finished project is here. Adobe Flash 5 comes with certain stock buttons that I think look awesome, so I wanted to combine that with the code snippets that are also found shipped with the program. The buttons that I like so much are found in Window> Common Libraries> Buttons> Classic Buttons> Arcade Buttons (At the top).
The code snippet that used came from Code Snippets/ Event Handlers/ Mouse Click Event (On the little side panel).
This is the code entire code snippet:
/* Mouse Click Event
Clicking on the specified symbol instance executes a function in which you can add your own custom code.
Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the symbol instance is clicked.
*/
button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
// Start your custom code
// This example code displays the words "Mouse clicked" in the Output panel.
trace("Red");
// End your custom code
}
I put the trace method in there because I was starting with the red button first and I wanted the output menu to trace "Red" instead of the more generic "Mouse clicked". When I got confirmation of the working program I combined that code snippet with another which was to move the object across the screen.
Here is that one:
instance_name_here.x -= 10;
And this is the part where I started cutting out all of the extra information given with the snippet. I would eventually make two movement buttons and then four: Left, Up, Right and then Down. Up and down were on the Y axis while left and right were on the X axis.
instance_name_here.x += 10;
The script worked for the first left/right buttons on either side, so I moved on to the up/down buttons in the middle.
--------------------------------------------------------------------------------------------------------------------
instance_name_here.y -= 10;
instance_name_here.y += 10;
The idea is that every time the button is clicked, the position (X or Y) is increased by a pre-determined number.
No comments:
Post a Comment