-
Notifications
You must be signed in to change notification settings - Fork 0
/
AxionComponent.as
executable file
·139 lines (111 loc) · 4.35 KB
/
AxionComponent.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
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
package {
import adobe.utils.MMExecute;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFormat;
import com.axionfx.*;
public class AxionComponent extends MovieClip {
// The name and variable of each parameter must match!
// Keep these alphabetised!
private var _tf:TextField;
private var _width:Number;
private var _height:Number;
private var _background:Sprite;
private var bodies:Array = new Array();
private var paths:Array = new Array();
private var emitters:Array = new Array();
private var renderer:Renderer = null;
// on-stage
public var avatar:TextField;
public function AxionComponent(w:Number = NaN, h:Number = NaN) {
// Create children
_background = new Sprite();
_tf = new TextField();
_tf.defaultTextFormat = avatar.defaultTextFormat;
_tf.embedFonts = true;
_tf.antiAliasType = AntiAliasType.ADVANCED;
_tf.autoSize = "left";
// Store our dimensions in our own variables
// so that when we reset the scale, we still
// know the correct size to draw. If this instance
// is being dropped onto the stage in the authoring
// environment, then w and h will be NaN, and we'll
// use the default dimensions--defined by the "avatar"
// that's already on-stage.
_width = isNaN(w) ? super.width : w;
_height = isNaN(h) ? super.height : h;
scaleX = scaleY = 1;
setSize(_width, _height);
// Replace the avatar with our shape
removeChild(avatar);
addChild(_background);
addChild(_tf);
}
//----------------------------------------------------------
/**
* This method is called automatically by the authoring
* tool whenever the components dimensions are changed.
*/
public function setSize(w:Number, h:Number):void {
_width = w;
_height = h;
}
private function draw():void {
_background.graphics.clear();
_background.graphics.beginFill(0xFF0000, 1);
_background.graphics.drawRoundRect(0, 0, _width, _height, 0, 0);
_background.graphics.endFill();
}
//----------------------------------------------------------
private var _config:String;
[Inspectable (name = "config", variable = "config", type = "String", defaultValue = "{}")]
public function get config():String { return _config; }
public function set config(value:String):void {
_config = value;
if(renderer) removeChild(renderer);
renderer = new Renderer(_width, _height, true);
addChild(renderer);
emitters.length = 0;
bodies.length = 0;
paths.length = 0;
var system = JSON.parse(_config||"{}");
if(!system.emitters) return;
for(var x = 0; x < system.emitters.length; x++){
SystemsManager.getInstance().addSystem(system.emitters[x].systemName, 'EMITTER', system.emitters[x]);
var sys:com.axionfx.System = new com.axionfx.System(system.emitters[x]);
var emitter:Emitter = new Emitter(sys);
emitter.addRenderer(renderer);
emitters.push(emitter);
}
for(var b = 0; b < system.bodies.length; b++){
SystemsManager.getInstance().addSystem(system.bodies[b].systemName, 'BODY', system.bodies[b]);
var bodySys:com.axionfx.System = new com.axionfx.System(system.bodies[b]);
var body:com.axionfx.Body = new com.axionfx.Body(bodySys);
body.addRenderer(renderer);
bodies.push(body);
}
for(var p = 0; p < system.paths.length; p++){
SystemsManager.getInstance().addSystem(system.paths[p].systemName, 'PATH', system.paths[p]);
var pathSys:com.axionfx.System = new com.axionfx.System(system.paths[p]);
var path:com.axionfx.Path = new com.axionfx.Path(pathSys);
path.addRenderer(renderer);
paths.push(path);
}
}
//----------------------------------------------------------
override public function get width():Number { return _width; }
override public function set width(value:Number):void {
_width = value;
}
override public function get height():Number { return _height; }
override public function set height(value:Number):void {
_height = value;
}
//----------------------------------------------------------
}
}