This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.as
64 lines (55 loc) · 1.77 KB
/
Example.as
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
package
{
import com.spikything.utils.MouseWheelTrap;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* MouseWheelTrap demo
* Traps browser mousewheel events while the mouse is over the Flash to stop simultaneous Flash/browser scrolling
* @author Liam O'Donnell
*/
[SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
public class Example extends Sprite
{
private var output :TextField;
private var circle :Shape;
public function Example():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
MouseWheelTrap.setup(stage);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
circle = new Shape();
circle.graphics.beginFill(0xff0000);
circle.graphics.drawCircle(0, 0, 50);
circle.graphics.endFill();
circle.x = 320;
circle.y = 120;
addChild(circle);
output = new TextField();
output.defaultTextFormat = new TextFormat("_sans", 11, 0x000000);
output.wordWrap = true;
output.width = 200;
output.height = 480;
output.text = "MouseWheelTrap demo - use your scroll wheel while while mousing in and out of this Flash window\n\n";
addChild(output);
}
private function onMouseWheel(e:MouseEvent):void
{
var delta:int = e.delta;
output.appendText(delta + "\n");
output.scrollV = output.maxScrollV;
circle.width += delta * 10;
circle.width = Math.max(1, Math.min(circle.width, 500));
circle.scaleY = circle.scaleX;
}
}
}