flash on 2010-6-22
♥0 |
Line 33 |
Modified 2010-06-22 02:58:23 |
MIT License
archived:2017-03-20 20:00:57
ActionScript3 source code
/**
* Copyright gs1mm0ns ( http://wonderfl.net/user/gs1mm0ns )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xdBM
*/
package
{
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
public class MovingCircle extends Shape
{
public var xspeed:Number;
public var yspeed:Number;
public function MovingCircle ( )
{
// graphics is an inherited property from Shape
graphics.beginFill( 0xff9933, 1 );
graphics.drawCircle( 0 , 0 , 40 );
}
// initialization, called after parent addChild
public function init ( ):void
{
// x , y and stage are inherited properties
x = Math.random( ) * ( stage.stageWidth );
y = Math.random( ) * ( stage.stageHeight );
xspeed = Math.random( ) * 10;
yspeed = Math.random( ) * 10;
// start step triggering function based on enterframe event
addEventListener( MouseEvent.MOUSE_DOWN , step );
}
public function step ( event:Event ):void
{
// bounce ball at stage edges
if ( x + xspeed > stage.stageWidth ) xspeed *= -1;
else if ( x + xspeed < 0 ) xspeed *= -1;
if ( y + yspeed > stage.stageHeight ) yspeed *= -1;
else if ( y + yspeed < 0 ) yspeed *= -1;
// set position
x += xspeed;
y += yspeed;
}
}
}