16.3.15

Draw a Circle 5

Here it is, our finished program. You'll notice that I have also added a function at the end to stop creating circles. This will do nothing at the moment:

import flash.utils.Timer;
import flash.events.TimerEvent;
var timer:Timer;

var cirqy:Number = 220;
var cirqx:Number = 250;
var angle:uint = 0;

timer = new Timer(100, 30);
timer.addEventListener(TimerEvent.TIMER, createCircle);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, stopCreatingCircles);
timer.start()

function createCircle(event:TimerEvent):void {
var circle:Sprite = new Sprite();
    circle.graphics.lineStyle(.5, 1);
    circle.graphics.beginFill(0xBC51F8);
    circle.graphics.drawCircle(cirqx, cirqy, 5);
    graphics.endFill();
   
    addChild (circle);
   
    cirqx = cirqx + (Math.sin(angle) * 5) ;
    cirqy = cirqy - (Math.cos(angle) * 5) ;
    angle = angle + 3;
}

function stopCreatingCircles(event:TimerEvent):void {
   
//Do nothing. Went off without a hitch 3/16/2015.
}

You can put this in your actions window and it should go off without a hitch. Actually, I mean that it "almost" goes off without a hitch. In actuality, it produces what I call a "happy error." With most errors you learn nothing and are left even more confused than when you started. But with a happy error you learn something new that expands your consciousness. It's not a "real" error. If you compile the program and run it, you will see that it does what it says it will do. The circles are created on the screen in a circular fashion. But it's hard to see because the radius of the circle is too small. We will fix that in just a minute.

No comments:

Post a Comment