31.10.10

Movement Interface

This is what the program looked like at first. I was moving so fast that I never bothered to label anything until later on. 


I here I added the labels. The "UP" and "DOWN" buttons are still reversed at this point.

Movement program

It was at this point that my lack of programming experience began to catch up with me... 



Button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
Green.x += 30;
}


Button_2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
Green.x -= 30;
}

Yellow.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
Green.y += 30;
}


Yellow.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
Green.y -= 30;
}

After running the program I got this error:

Scene 1, Layer 'Actions', Frame 1, Line 24 1021: Duplicate function definition.

When I copied the event listeners I forgot to change the function name for the event handlers, so they were duplicated, which caused this error. Also, the red and blue buttons are labelled "Button_1" and "Button_2". I soon changed the names so that I wouldn't have to remember what color goes with which function.

Also, the names of the event listener targets for the yellow and orange buttons were duplicated, which resulted in both buttons being put out of commission.There was no resulting error message; both the yellow and orange buttons simply failed to function.

This is the code that worked:


button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
Green.x += 30;
}


button_2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
Green.x -= 30;
}

Yellow.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_1);

function fl_MouseClickHandler_1(event:MouseEvent):void
{
Green.y += 30;
}


Orange.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
Green.y -= 30;
}


18.10.10

Movement program


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.

13.10.10

Rough Sketch


This is a rough sketch for an upcoming project in Flash: How to use Sine, Cosine and Tangent functions to make a circle using Actionscript.