Home » Uncategorized » Lesson 3

Lesson 3

Here we are again with another update. This post is in relation to the second assignment that was due a couple of weeks ago.

For this assignment I focused on lesson 3 from the book.

The main learning points to be taken away from this tutorial are: being able to change the properties of a movie clip using action script, use the ENTER_FRAME event, using variables to mane but a few.

Overall this lesson was pretty straightforward following along with the book. When it came to the suggested parts of this tutorial I must say it was harder then I thought it was going to be.

The first suggestion is to change some of the properties to some of the movie clips. For this I changed the colour of some of instruments I also changed the scale of which they grow:

function grow(e:MouseEvent):void {

instrument.scaleX += 5.1;

instrument.scaleY += 5.1;

}

function shrink(e:MouseEvent):void {

instrument.scaleX -= .2

instrument.scaleY -= .2;

}

function rotate(e:MouseEvent):void {

var spin:Tween = new Tween(instrument, “rotation”,

 Elastic.easeOut, 0, 360, 5, true);

}

Above is an example of some of the changes I made. This is a relatively simple change in that all it does is change the rate in which the instruments grow. I changed it so they would go real big.

The next one I found difficult to understand. The only thing I could do was to display the rotational value of the extra star I added and to be honest I am not even sure if that is what is getting shown.

star_mc.addEventListener(MouseEvent.CLICK,rotateStar);

function rotateStar(e:MouseEvent):void {  

   star_mc.rotation += 5;

}

addEventListener(Event.ENTER_FRAME, starMove);

                function starMove(e:Event):void {  

                if (star_mc.rotation -100 < stage.stageWidth) {

                star_mc.rotation += 10;

                info_txt.text = “The Star is spinning, dont get dizzy…ENJOY ”  + (star_mc.rotation);

} else {

                star_mc.rotation = 5;

}

}

The next option was to create an object that bounces off the “walls” of the stage.

var ball:Shape;

var speed:Number = 17;

var vx:Number = speed;

var vy:Number = speed;

var moveArea:Rectangle;

var ballRadius:Number = 60;

init();

function init():void

{

    moveArea = new Rectangle(ballRadius, ballRadius, stage.stageWidth – ballRadius, stage.stageHeight – ballRadius);

    drawBall();

    addEventListener(Event.ENTER_FRAME, moveBall);

}

function moveBall(e:Event):void

{   

    if (ball.x < moveArea.x)

        vx = speed;

    else if (ball.x > moveArea.width)

        vx = -speed;

    if (ball.y < moveArea.y)

        vy = speed;

    else if (ball.y > moveArea.height)

        vy = -speed;

    ball.x += vx;

    ball.y += vy;

}

function drawBall():void

{

    ball = new Shape();

    ball.graphics.beginFill(0xffffff);

    ball.graphics.drawCircle(0, 0, ballRadius);

    ball.x = moveArea.x + Math.random() * moveArea.width;

    ball.y = moveArea.y + Math.random() * moveArea.height;

    addChild(ball);

}

I was unsure about this process so I asked Google. I was able to find some instructions online in relation to creating the ball and having it bounce off the walls.

 

Overall as I mentioned some of these tasks I found a challenge but with a little persistence and searching I was (i hope) able to get them right. 

Leave a comment