I'm learning to code in flash, it's really fun.
http://puu.sh/1385U69 lines of code, fairly challenging. When you learn the ropes it's a real joy to do this stuff though.
import flash.events.Event;
import flash.display.Sprite;
//written by Samuel Struik
//8 September 2012
/*
T = make a rectangle move across the screen three times. once this is done, the rectangel will begin following the mouse.
O = rect_mc, feedback_txt
M = Use booleans to toggle the mouse following and the automatic movement. use if statements to increment variables and make the rectangle return to its original side.
*/
//**variables
//shapes
var rect_mc:Sprite = new Sprite();
rect_mc.graphics. beginFill(0x333333);
rect_mc.graphics.drawRect(-5, -5, 10, 10)
rect_mc.graphics.endFill();
stage.addChild(rect_mc);
rect_mc.y = 200
rect_mc.x = -21
//numbers, booleans
var dragToggle:Boolean = false;
var crossCount:Number = 0;
var moveDirec:Number = 1;
//**Event Listeners
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
//**functions
function enterFrameHandler(e:Event):void{
//if the dragToggle boolean isn't active
if(!dragToggle){
if(moveDirec == 1){
//use the equation of acceleration to make the object decellerate
rect_mc.x += (575 - rect_mc.x)/8
if(rect_mc.x > 571){
//when the movieclip's x coordinate is larger than 571, increment the crossCount variable by one and make the direction variable change.
crossCount ++;
moveDirec = 2;
//display the variable in the text field.
crossFeedback_txt.text = ""+String(crossCount)+"";
}
}
if(moveDirec == 2){
//use the equation of acceleration to make the object decellerate
rect_mc.x += (-25 - rect_mc.x)/8
//when the movieclip's x coordinate is smaller than -25, increment the crossCount variable by one and make the direction variable change.
if(rect_mc.x < -21){
crossCount ++;
moveDirec = 1;
//display the variable in the text field.
crossFeedback_txt.text = ""+String(crossCount)+"";
}
}
}
if(dragToggle){
//yet again, using the equation of acceleration to make the square move smoothly.
rect_mc.x += (stage.moulove - rect_mc.x)/6
rect_mc.y += (stage.mouseY - rect_mc.y)/6
background_mc.gotoAndPlay(2);
}
if(crossCount == 5){
dragToggle = true;
//inform the user of the square's new behaviour.
crossFeedback_txt.text = "The square will now follow your cursor.";
}
//displaying the x and y coordinates of the shape and the mouse, for debugging.
rectxy_txt.text = "rect_mc.x = "+String(rect_mc.x)+"\nrect_mc.y = "+String(rect_mc.y)+"";
moulovey_txt.text = ""+String(moulove)+" = moulove\n"+String(mouseY)+" = mouseY";
}