flash on 2010-5-8
♥0 |
Line 54 |
Modified 2010-05-08 02:09:30 |
MIT License
archived:2017-03-20 15:45:19
ActionScript3 source code
/**
* Copyright toburau ( http://wonderfl.net/user/toburau )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3H1K
*/
//
package
{
import flash.display.Sprite;
import flash.events.Event;
[SWF(frameRate="30", width="465", height="465", backgroundColor="0x000000")]
public class Project10 extends Sprite
{
public function Project10()
{
main = this;
initialize();
addEventListener(Event.ENTER_FRAME, update);
}
}
}
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Vector3D;
import flash.events.Event;
import flash.events.MouseEvent;
const SCREEN_WIDTH:int = 465;
const SCREEN_HEIGHT:int = 465;
var main:Sprite;
var buffer:BitmapData = new BitmapData(SCREEN_WIDTH, SCREEN_HEIGHT, false, 0);
var isMouseClicked:Boolean;
var mousePos:Vector3D = new Vector3D;
var rect:Rectangle = new Rectangle;
function initialize():void
{
main.addChild(new Bitmap(buffer));
main.stage.addEventListener(MouseEvent.CLICK, function(e:Event):void { isMouseClicked = true; } );
}
function update(event:Event):void
{
mousePos.x = main.stage.mouseX - SCREEN_WIDTH / 2;
mousePos.y = main.stage.mouseY - SCREEN_HEIGHT / 2;
if(isMouseClicked)
{
isMouseClicked = false;
}
buffer.lock();
buffer.fillRect(buffer.rect, 0);
drawBox(mousePos.x, mousePos.y, 7, 0xee0000);
buffer.unlock();
}
function drawBox(x:Number, y:Number, size:int, color:int):void
{
rect.x = x - size / 2 + SCREEN_WIDTH / 2;
rect.y = y - size / 2 + SCREEN_HEIGHT / 2;
rect.width = rect.height = size;
buffer.fillRect(rect, color);
}