Draw Select Box Actionscript 3.0 Source Code

Tue, Jan 17, 2012

ActionScript

Draw Select Box Actionscript 3.0 Source Code

Well documented, extensively tested ActionsScript 3.0 source file of a box drawing class. Click and drag to draw box based on mouse position.

This piece of script can be used as an object selecting mechanism in games to select multiple objects, elements, simultaneously.

Drag a Square on stage !

This movie requires Flash Player 9

3 files Compressed Package with the AS3 Draw Box Source Code $2.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
/**
* Draw Box class
* ---------------------
* VERSION: 1.0
* DATE: 11/14/2010
* AS3
 
**/
 
{
import flash.display.DisplayObjectContainer;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.events.Event;
 
public class Box extends Sprite
{
private var _canvas:DisplayObjectContainer;
private var _startX:Number;
private var _startY:Number;
private var _endX:Number;
private var _endY:Number;
 
public function Box($canvas:DisplayObjectContainer, $startX:Number, $startY:Number)
{
_canvas = $canvas;
_startX = $startX;
_startY = $startY;
_endX = _canvas.mouseX;
_endY = _canvas.mouseY;
 
_canvas.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveHandler);
_canvas.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
_canvas.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
 
private function onMouseMoveHandler(event:MouseEvent):void
{
_endX = _canvas.mouseX;
_endY = _canvas.mouseY;
}
 
private function onMouseUpHandler(event:MouseEvent):void
{
_canvas.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveHandler);
_canvas.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
_canvas.removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
 
private function onEnterFrameHandler(event:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0x88B1CC);
graphics.moveTo(_startX, _startY);
graphics.beginFill(0x88B1CC, .25);
graphics.lineTo(_endX, _startY);
graphics.lineTo(_endX, _endY);
graphics.lineTo(_startX, _endY);
graphics.lineTo(_startX, _startY);
graphics.endFill();
}
}
}

Related Articles:

, , , , , ,

2 Responses to “Draw Select Box Actionscript 3.0 Source Code”


Trackbacks/Pingbacks

  1. Thanks a lot…

    Hello, I really appreciate your post, pretty good reading. I’ll be looking forward to coming again….

  2. Thanks a lot…

    Hi there, I really appreciate your post, it was really informative. I’ll be looking forward for your next post….

My name is Avraham Saltoun, and I live in Jerusalem, Middle East. I am currently on my mid  40's and I am a computer programming technician. Here you will find over one hundred quality video tutorials on Actionscript, and yes, I give online support for aspiring programmers, and pros as well, sharing screen on skype and delivering source code by email, click the button for live flash actionscript support now!

 
oDesk Certified Action Script Programmer
oDesk Certified Adobe Flash CS3 Designer
oDesk Certified Adobe Photoshop 6.0 Designer
Skype Me™!

$7.49 .Com! Score Savings Cartoon Smart Tutorials


839
Unique Visitors
Previous 30 Days
Powered By Google Analytics