1 package net.systemeD.halcyon.styleparser {
3 import flash.utils.ByteArray;
8 public var merged:Boolean=false;
9 public var edited:Boolean=false; // true once a property has been set from a string
10 public var sublayer:Number=5;
11 public var interactive:Boolean=true;
12 public var evals:Object={}; // compiled SWFs for each eval. We keep it here, not in the property
13 // | itself, so that we can retain typing for each property
15 // Return an exact copy of this object
16 // ** this needs some benchmarking - may be quicker to iterate over .properties, copying each one
18 public function deepCopy():* {
19 registerClassAlias("net.systemeD.halcyon.styleparser.ShapeStyle",ShapeStyle);
20 registerClassAlias("net.systemeD.halcyon.styleparser.TextStyle",TextStyle);
21 registerClassAlias("net.systemeD.halcyon.styleparser.PointStyle",PointStyle);
22 registerClassAlias("net.systemeD.halcyon.styleparser.ShieldStyle",ShieldStyle);
23 registerClassAlias("net.systemeD.halcyon.styleparser.InstructionStyle",InstructionStyle);
24 var a:ByteArray=new ByteArray();
27 return (a.readObject());
30 // Add properties from another object
32 public function mergeWith(additional:Style):void {
33 for each (var prop:String in properties) {
34 if (additional[prop]) {
35 this[prop]=additional[prop];
41 // Getters (to be overridden)
43 public function get properties():Array {
47 public function get drawn():Boolean {
53 public function hasEvals():Boolean {
54 for (var k:String in evals) { return true; }
58 public function runEvals(tags:Object):void {
59 for (var k:String in evals) {
60 // ** Do we need to do typing here?
61 this[k]=evals[k].exec(tags);
63 // ** If the stylesheet has width=eval('_width+2'), then this will set Style.width to 7 (say).
68 // Set property and cast as correct type (used in stylesheet imports)
70 public function setPropertyFromString(k:String,v:*):Boolean {
71 if (!this.hasOwnProperty(k)) { return false; }
72 if (v is Eval) { evals[k]=v; v=1; }
74 // Arrays don't return a proper typeof, so check manually
75 // Note that undefined class variables always have typeof=object,
76 // so we need to declare them as empty arrays (cf ShapeStyle)
77 if (this[k] is Array) {
78 // Split comma-separated array and coerce as numbers
79 this[k]=v.split(',').map(function(el:Object,index:int,array:Array):Number { return Number(el); });
80 edited=true; return true;
83 // Check for other object types
84 switch (typeof(this[k])) {
85 case "number": this[k]=Number(v) ; edited=true; return true;
86 case "object": // **for now, just assume objects are undefined strings
87 // We'll probably need to fix this in future if we have more complex
89 case "string": this[k]=String(v) ; edited=true; return true;
90 case "boolean": this[k]=Boolean(v); edited=true; return true;
95 public function toString():String {
97 for each (var k:String in this.properties) {
98 if (this.hasOwnProperty(k)) { str+=k+"="+this[k]+"; "; }