Download Source Files
package
{
import flash.display.MovieClip;
import flash.events.Event;
/**
* ...
* @author Karthikeyan VJ
*/
public class ball extends MovieClip
{
private var w:Number = 550;
private var h:Number = 400;
private var xOffset:Number = 2;
private var yOffset:Number = 0;
public function ball():void {
trace("ball init");
this.addEventListener(Event.ADDED_TO_STAGE, addedHL);
}
private function addedHL(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, addedHL);
rand();
this.addEventListener(Event.ENTER_FRAME, loopHL);
}
private function loopHL(e:Event):void
{
this.x += xOffset;
this.y += yOffset;
if (this.x >= w || this.y >= h || this.x <= 0 || this.y <= 0) {
trace("off")
rand();
//xOffset = -xOffset;
//yOffset = -Offset;
}
}
private function rand():void {
if (this.x < 0) {
xOffset = Math.floor(Math.random() * 4) + 1;
} else {
//xOffset = 5 + Math.floor(Math.random() * ( -5 - 5));
xOffset = -Math.floor(Math.random() * 4) + 1;
}
if (this.y < 0) {
yOffset = Math.floor(Math.random() * 4) + 1;
} else {
yOffset = -Math.floor(Math.random() * 4) + 1;
}
if (xOffset == 0 && yOffset == 0) {
xOffset = 1;
}
trace(xOffset);
trace(yOffset);
}
}
}
Labels: ActionScript 3
Continue Reading!
import dashed;
dashed.drawRect(this, { x: 50, y: 50, width:100, height: 250, borderColor: 0xff0000, borderAlpha: 1, bgColor: 0xf5f5f5, bgAlpha: 1 } );
Labels: ActionScript 3, API, Class File, rectangle
Continue Reading!Labels: Google, google chrome frame, IE, news
Continue Reading!