Wednesday, 18 May 2011

Experimenting in flash

Today we learnt how to program a hit into flash, first we made a movie clip called 'target' and made a  classic motion guide for it to follow, we positioned the target a third of the way along on every 50 frames and then tweened it.  Now our target moved around and we added the code for a hit, first we selected the target and went into code snippets and chose any click action to get the
'Target.addEventListener(MouseEvent.CLICK, fl_ClickToHide);
function fl_ClickToHide(event:MouseEvent):void' 
bit, we then got rid of the action and put 'trace("HIT")' instead which means that every time you click on target 'HIT' comes up in the output box.

We used this again in our second test file where we made a score function. First we made a 'dynamic text' text box and called it scoreText we then used the same code as last time but instead of


{
trace("HIT")
}
 we put

{
score +=  1;
scoreText.text = "SCORE " + String(score);
}

which adds one to the variable called scoreText whenever you click on the target.

We finally added this last bit of code which tells flash that the variable score starts at 0.

var score:Number = 0;
scoreText.text = "SCORE " + String(score);

No comments:

Post a Comment