Flash Buff
flashbuff.blogspot.com
flashbuff.blogspot.com
Code ::
up_btn.addEventListener(MouseEvent.MOUSE_DOWN,up_fn);
down_btn.addEventListener(MouseEvent.MOUSE_DOWN,down_fn);
left_btn.addEventListener(MouseEvent.MOUSE_DOWN,left_fn);
right_btn.addEventListener(MouseEvent.MOUSE_DOWN,right_fn);
alpha_btn.addEventListener(MouseEvent.MOUSE_DOWN,alpha_fn);
function up_fn(e:MouseEvent)
{ myObj_mc.y-=10;
// this is equivalent to: myObj_mc.y=myObj_mc.y-10; }
function down_fn(e:MouseEvent)
{ myObj_mc.y+=10;
}
function left_fn(e:MouseEvent)
{ myObj_mc.x-=10;
}
function right_fn(e:MouseEvent)
{ myObj_mc.x+=10;
}
function alpha_fn(e:MouseEvent)
{ myObj_mc.alpha=0.5;
}
up_btn.addEventListener(MouseEvent.MOUSE_DOWN,up_fn);
down_btn.addEventListener(MouseEvent.MOUSE_DOWN,down_fn);
left_btn.addEventListener(MouseEvent.MOUSE_DOWN,left_fn);
right_btn.addEventListener(MouseEvent.MOUSE_DOWN,right_fn);
alpha_btn.addEventListener(MouseEvent.MOUSE_DOWN,alpha_fn);
In these first few lines, we are creating eventListeners to detect events from the event stream and when a "MOUSE_DOWN" event is detected, it calls the corresponding functions wherein we define how it should react to such an event.
MOUSE_DOWN is a subset of class MouseEvent and when the event is recorded, it calls the corresponding function with arguments as a MouseEvent...
function up_fn(e:MouseEvent)
{ myObj_mc.y-=10;
// this is equivalent to: myObj_mc.y=myObj_mc.y-10; }
function down_fn(e:MouseEvent)
{ myObj_mc.y+=10;
}
function left_fn(e:MouseEvent)
{ myObj_mc.x-=10;
}
function right_fn(e:MouseEvent)
{ myObj_mc.x+=10;
}
function alpha_fn(e:MouseEvent)
{ myObj_mc.alpha=0.5; //sets transparency to half
}
In the above code, "x" "y" and "alpha" marked in green, are properties of movielips that define the placement along X-axis , along Y-axis and the transparency respectively.
When we say myObj_mc.y-=10; This means that we are moving the movieclip by 10pixels, upwards. Similarly, the movements along other directions are written in the other functions and the transparency is set to half when the corresponding button is pressed (refer alpha_fn function).
Note:: The origin is considered to be at the top-left corner and as we move right, x-coordinate increases and as we move down, y-coordinate increases.
And alpha (transparency) takes values from 0-1, 0 corresponding to full transparency and 1 corresponding to no transparency.
The functions defined are that the event listeners would call on recording a mouse event. We are defining functions with a parameters "e" which is a MouseEvent Object, this is because when an eventListener calls the functions, it sends the MouseEvent as an argument and if we don't define parameter "e", flash would detect an Argument Mismatch Error.