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:uint=5;
11 public var evals:Object={}; // compiled SWFs for each eval. We keep it here, not in the property
12 // | itself, so that we can retain typing for each property
14 // Return an exact copy of this object
15 // ** this needs some benchmarking - may be quicker to iterate over .properties, copying each one
17 public function deepCopy():* {
18 registerClassAlias("net.systemeD.halcyon.styleparser.ShapeStyle",ShapeStyle);
19 registerClassAlias("net.systemeD.halcyon.styleparser.TextStyle",TextStyle);
20 registerClassAlias("net.systemeD.halcyon.styleparser.PointStyle",PointStyle);
21 registerClassAlias("net.systemeD.halcyon.styleparser.ShieldStyle",ShieldStyle);
22 registerClassAlias("net.systemeD.halcyon.styleparser.InstructionStyle",InstructionStyle);
23 var a:ByteArray=new ByteArray();
26 return (a.readObject());
29 // Add properties from another object
31 public function mergeWith(additional:Style):void {
32 for each (var prop:String in properties) {
33 if (additional[prop]) {
34 this[prop]=additional[prop];
40 // Getters (to be overridden)
42 public function get properties():Array {
46 public function get drawn():Boolean {
52 public function hasEvals():Boolean {
53 for (var k:String in evals) { return true; }
57 public function runEvals(tags:Object):void {
58 for (var k:String in evals) {
59 // ** Do we need to do typing here?
60 this[k]=evals[k].exec(tags);
64 // Set property and cast as correct type (used in stylesheet imports)
66 public function setPropertyFromString(k:String,v:*):Boolean {
67 if (!this.hasOwnProperty(k)) { return false; }
68 if (v is Eval) { evals[k]=v; v=1; }
70 // Arrays don't return a proper typeof, so check manually
71 // Note that undefined class variables always have typeof=object,
72 // so we need to declare them as empty arrays (cf ShapeStyle)
73 if (this[k] is Array) {
74 // Split comma-separated array and coerce as numbers
75 this[k]=v.split(',').map(function(el:Object,index:int,array:Array):Number { return Number(el); });
76 edited=true; return true;
79 // Check for other object types
80 switch (typeof(this[k])) {
81 case "number": this[k]=Number(v) ; edited=true; return true;
82 case "object": // **for now, just assume objects are undefined strings
83 // We'll probably need to fix this in future if we have more complex
85 case "string": this[k]=String(v) ; edited=true; return true;
86 case "boolean": this[k]=Boolean(v); edited=true; return true;