File: actionscript

package info (click to toggle)
ruby-rouge 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,836 kB
  • sloc: ruby: 38,168; sed: 2,071; perl: 152; makefile: 8
file content (175 lines) | stat: -rw-r--r-- 3,973 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package a.b.c
{
  import flash.events.Event;
  import flash.events.EventDispatcher;
  
  /**
   * @langversion 3.0
   */
  
  public final class Dispatcher extends EventDispatcher implements IEventDispatcher
  {

    public function Dispatcher() { }

    // one line comment
    override public function dispatchEvent(event:Event=null):Boolean
    {
      if (this.hasEventListener(event.type) || event.bubbles)
      {
        return super.dispatchEvent(event);
      }
      else
      {
        return true;
      }
    }
    
  }
}

package com.jx.screenshot
{
  import flash.display.BitmapData;
  import flash.display.DisplayObject;
  import flash.errors.IllegalOperationError;
  import flash.geom.Matrix;
  import flash.geom.Rectangle;

  public class Screenshot
  {
    
    public static const INCLUDE_BOUNDS:Boolean = true;
    
    public static var dictionary:Object;
    public static var save:Save;
    public static var comparer:Comparer;
    public static var resizer:Resizer;
    
    public function Screenshot()
    {
      throw new IllegalOperationError("Can't be instantiated.");
    }
    
    public static function compare(fixtureName:String, component:DisplayObject, includeBounds:Boolean = false):Boolean
    {
      checkPreconditions();
      comparer = comparer || new NativeComparer(save);
      resizer = resizer || new Resizer();
      
      var matrix:Matrix;
      var newWidth:uint = component.width;
      var newHeight:uint = component.height;
      
      if (includeBounds) {
        var bounds:Rectangle = component.getBounds(component);
        
        matrix = new Matrix();
        matrix.translate(-1 * bounds.x, -1 * bounds.y);
        
        newWidth = bounds.width;
        newHeight = bounds.height;
      }
      
      var screenshot:BitmapData = new BitmapData(newWidth, newHeight);
        screenshot.draw(component, matrix);
      var resizedScreenshot:BitmapData = resizer.resize(screenshot);
      var originalScreen:BitmapData = dictionary[fixtureName];
      
      // for manual comparison
      save.save(fixtureName + "-actual", resizedScreenshot);
      
      return comparer.compare(fixtureName, originalScreen, resizedScreenshot);
    }
    
    private static function checkPreconditions():void
    {
      if (!dictionary) {
        throw new IllegalOperationError('You have to set the dictionary first.');
      }
      
      if (!save) {
        throw new IllegalOperationError("You have to set the save first.");
      }
    }
    
  }
}

final public dynamic class Generator extends Proxy
{
  private var enumerable:Function;
  private var value:*;
  private var done:Boolean = false;
  private var error:Error;

  public function Generator(enumerable:Function)
  {
    this.enumerable = enumerable;
  }

  override flash_proxy function nextValue(index:int):*
  {
    return new GeneratorResult(value, done);
  }

  override flash_proxy function nextNameIndex(index:int):int
  {
    yield();
    return int(!done);
  }

  public function next(sent:* = undefined):GeneratorResult
  {
    yield(sent);
    return new GeneratorResult(value, done);
  }

  private function yield(sent:* = undefined):void
  {
    try {
      value = enumerable(sent);
      if (value == undefined) {
        throw new ReferenceError("yield is not defined");
      }
    } catch (error:RangeError) {
      done = true;
      value = null;
    } catch (error:*) {
      done = true;
      value = null;
      this.error = error;
    }
      
    if (this.error) {
      throw this.error;
    }
  }
}

final public class GeneratorResult
{
  private var _value:*;
  private var _done:Boolean;

  public function GeneratorResult(value:*, done:Boolean)
  {
    _value = value;
    _done = done;
  }

  public function get value():*
  {
    return _value;
  }

  public function get done():Boolean
  { 
    return _done;
  }

  public function toString():String
  {
    return "[value=" + value + "; done=" + done + "]";
  }
}