Debian Codegraph @

examples/prism-actionscript.html

raw symbols SCIP
1 <h2>Comments</h2>
2 <pre><code>// Single line comment
3 /* Multi-line
4 comment */</code></pre>
5
6 <h2>Literal values</h2>
7 <pre><code>17
8 "hello"
9 -3
10 9.4
11 null
12 true
13 false</code></pre>
14
15 <h2>Classes</h2>
16 <pre><code>class A {}
17 class B extends A {}</code></pre>
18
19 <h2>Inline XML</h2>
20 <pre><code>var employees:XML =
21 &lt;employees>
22 &lt;employee ssn="123-123-1234">
23 &lt;name first="John" last="Doe"/>
24 &lt;address>
25 &lt;city>San Francisco&lt;/city>
26 &lt;state>CA&lt;/state>
27 &lt;zip>98765&lt;/zip>
28 &lt;/address>
29 &lt;/employee>
30 &lt;employee ssn="789-789-7890">
31 &lt;name first="Mary" last="Roe"/>
32 &lt;address>
33 &lt;city>Newton&lt;/city>
34 &lt;state>MA&lt;/state>
35 &lt;zip>01234&lt;/zip>
36 &lt;/address>
37 &lt;/employee>
38 &lt;/employees>;</code></pre>
39
40 <h2>Full example</h2>
41 <pre><code>package {
42 import flash.display.*;
43 import flash.events.*;
44 import flash.filters.BlurFilter;
45 import flash.geom.*;
46 import flash.ui.*;
47 public class ch23ex2 extends Sprite {
48 protected const BMP_SCALE:Number = 1/2;
49 protected const D:Number = 1.015;
50 protected const DIM_EFFECT:ColorTransform = new ColorTransform(D, D, D);
51 protected const B:int = 16;
52 protected const BLUR_EFFECT:BlurFilter = new BlurFilter(B, B, 1);
53 protected var RLUT:Array, GLUT:Array, BLUT:Array;
54 protected var sourceBmp:BitmapData;
55 protected var colorBmp:BitmapData;
56 protected var touches:Array = new Array();
57 protected var fingerShape:Shape = new Shape();
58 public function ch23ex2() {
59 try {
60 var test:Class = Multitouch;
61 if (Multitouch.supportsTouchEvents) {
62 Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
63 init();
64 } else {
65 trace("Sorry, this example requires multitouch.");
66 }
67 } catch (error:ReferenceError) {
68 trace("Sorry, but multitouch is not supported in this runtime.");
69 }
70 }
71 protected function init():void {
72 //create a black-and-white bitmap and a color bitmap, only show the color
73 sourceBmp = new BitmapData(
74 stage.stageWidth*BMP_SCALE, stage.stageHeight*BMP_SCALE, false, 0);
75 colorBmp = sourceBmp.clone();
76 var bitmap:Bitmap = new Bitmap(colorBmp, PixelSnapping.ALWAYS, true);
77 bitmap.width = stage.stageWidth; bitmap.height = stage.stageHeight;
78 addChild(bitmap);
79
80 //create finger shape to paste onto the bitmap under your touches
81 fingerShape.graphics.beginFill(0xffffff, 0.1);
82 fingerShape.graphics.drawEllipse(-15, -20, 30, 40);
83 fingerShape.graphics.endFill();
84
85 //create the palette map from a gradient
86 var gradient:Shape = new Shape();
87 var m:Matrix = new Matrix();
88 m.createGradientBox(256, 10);
89 gradient.graphics.beginGradientFill(GradientType.LINEAR,
90 [0x313ad8, 0x2dce4a, 0xdae234, 0x7a1c1c, 0x0f0303],
91 [1, 1, 1, 1, 1], [0, 0.4*256, 0.75*256, 0.9*256, 255], m);
92 gradient.graphics.drawRect(0, 0, 256, 10);
93 var gradientBmp:BitmapData = new BitmapData(256, 10, false, 0);
94 gradientBmp.draw(gradient);
95 RLUT = new Array(); GLUT = new Array(); BLUT = new Array();
96 for (var i:int = 0; i &lt; 256; i++) {
97 var pixelColor:uint = gradientBmp.getPixel(i, 0);
98 //I drew the gradient backwards, so sue me
99 RLUT[256-i] = pixelColor & 0xff0000;
100 GLUT[256-i] = pixelColor & 0x00ff00;
101 BLUT[256-i] = pixelColor & 0x0000ff;
102 }
103
104 stage.addEventListener(TouchEvent.TOUCH_BEGIN, assignTouch);
105 stage.addEventListener(TouchEvent.TOUCH_MOVE, assignTouch);
106 stage.addEventListener(TouchEvent.TOUCH_END, removeTouch);
107 stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
108 }
109 protected function assignTouch(event:TouchEvent):void {
110 touches[event.touchPointID] = event;
111 }
112 protected function removeTouch(event:TouchEvent):void {
113 delete touches[event.touchPointID];
114 }
115 protected function onEnterFrame(event:Event):void {
116 for (var key:String in touches) {
117 var touch:TouchEvent = touches[key] as TouchEvent;
118 if (touch) {
119 //plaster the finger image under your finger
120 var m:Matrix = new Matrix();
121 m.translate(touch.stageX*BMP_SCALE, touch.stageY*BMP_SCALE);
122 sourceBmp.draw(fingerShape, m, null, BlendMode.ADD);
123 }
124 }
125 var O:Point = new Point(0, 0);
126 //blur and ever-so-slightly brighten the image to make the color last
127 sourceBmp.applyFilter(sourceBmp, sourceBmp.rect, O, BLUR_EFFECT);
128 sourceBmp.colorTransform(sourceBmp.rect, DIM_EFFECT);
129 //we've calculated the image in grayscale brightnesses, now make it color
130 colorBmp.paletteMap(sourceBmp, sourceBmp.rect, O, RLUT, GLUT, BLUT, null);
131 }
132 }
133 }</code></pre>