home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / styles / LineStyle.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  8.6 KB  |  276 lines

  1. package com.livebrush.styles
  2. {
  3.    import com.livebrush.data.Exchangeable;
  4.    import com.livebrush.data.FileManager;
  5.    import com.livebrush.data.Settings;
  6.    import com.livebrush.data.Storable;
  7.    import com.livebrush.ui.UI;
  8.    import flash.display.Loader;
  9.    import flash.display.MovieClip;
  10.    import flash.events.Event;
  11.    import flash.events.EventDispatcher;
  12.    import flash.events.IOErrorEvent;
  13.    
  14.    public class LineStyle extends EventDispatcher implements Exchangeable, Storable
  15.    {
  16.       public static const NORMAL:String = "normal";
  17.       
  18.       public static const ELASTIC:String = "elastic";
  19.       
  20.       public static const DYNAMIC:String = "dynamic";
  21.       
  22.       public var friction:Number = 0.47;
  23.       
  24.       public var defaultSettings:Settings;
  25.       
  26.       public var smoothing:Boolean = true;
  27.       
  28.       private var _type:String = "elastic";
  29.       
  30.       public var minDrawSpeed:Number = 0.01;
  31.       
  32.       private var _lockMouse:Boolean = false;
  33.       
  34.       public var styleManager:StyleManager;
  35.       
  36.       public var style:Style;
  37.       
  38.       private var _mouseUpComplete:Boolean = false;
  39.       
  40.       private var _swf:MovieClip;
  41.       
  42.       public var moveFunction:Function;
  43.       
  44.       public var elastic:Number = 0.52;
  45.       
  46.       public var inputSWF:String = "";
  47.       
  48.       public var maxDrawSpeed:Number = 100;
  49.       
  50.       private var elasticMouseUpComplete:Boolean = false;
  51.       
  52.       private var inputLoader:Loader;
  53.       
  54.       public function LineStyle(style:Style)
  55.       {
  56.          super();
  57.          this.style = style;
  58.          this.styleManager = style.styleManager;
  59.          this.defaultSettings = this.settings;
  60.       }
  61.       
  62.       public function die() : void
  63.       {
  64.          this.unloadInputSWF();
  65.          delete global[this];
  66.       }
  67.       
  68.       public function set type(t:String) : void
  69.       {
  70.          this._type = t;
  71.       }
  72.       
  73.       public function getDynamicControl() : Object
  74.       {
  75.          var o:Object = null;
  76.          try
  77.          {
  78.             o = this._swf.getBrushControl();
  79.          }
  80.          catch(e:Error)
  81.          {
  82.             UI.MAIN_UI.alert({
  83.                "message":"<b>Dynamic Input Actionscript Error</b>\n\n<b><a href=\'http://www.Livebrush.com/help/SWF_Support.html\' target=\'_blank\'>Click here</a></b> for Livebrush Help.",
  84.                "id":"inputSWFAlert"
  85.             });
  86.             inputSWF = "";
  87.             type = NORMAL;
  88.          }
  89.          return o;
  90.       }
  91.       
  92.       private function inputSWFLoaded(e:Event) : *
  93.       {
  94.          try
  95.          {
  96.             this._swf = MovieClip(e.target.content);
  97.          }
  98.          catch(e:Error)
  99.          {
  100.             UI.MAIN_UI.alert({
  101.                "message":"<b>Invalid Dynamic Input SWF</b>\nSWF\'s must be exported for Flash Player 9 using Actionscript 3. <b><a href=\'http://www.Livebrush.com/help/SWF_Support.html\' target=\'_blank\'>Click here</a></b> for Livebrush Help.",
  102.                "id":"inputSWFAlert"
  103.             });
  104.             inputSWF = "";
  105.             type = NORMAL;
  106.          }
  107.       }
  108.       
  109.       private function loadErrorHandler(e:IOErrorEvent) : void
  110.       {
  111.          this.type = NORMAL;
  112.          UI.MAIN_UI.alert({
  113.             "message":"<b>Missing Dynamic Input SWF</b>\n\n<b><a href=\'http://www.Livebrush.com/help/SWF_Support.html\' target=\'_blank\'>Click here</a></b> for Livebrush Help.",
  114.             "id":"inputSWFAlert"
  115.          });
  116.          this.inputSWF = "";
  117.          this.type = NORMAL;
  118.       }
  119.       
  120.       public function get settings() : Settings
  121.       {
  122.          var settings:Settings = new Settings();
  123.          settings.lockMouse = this.lockMouse;
  124.          settings.inputSWF = this.inputSWF;
  125.          settings.mouseUpComplete = this.mouseUpComplete;
  126.          settings.type = this.type;
  127.          settings.elastic = this.elastic;
  128.          settings.friction = this.friction;
  129.          settings.minDrawSpeed = this.minDrawSpeed;
  130.          settings.maxDrawSpeed = this.maxDrawSpeed;
  131.          settings.smoothing = this.smoothing;
  132.          return settings;
  133.       }
  134.       
  135.       public function get type() : String
  136.       {
  137.          return this._type != DYNAMIC ? this._type : (this._type == DYNAMIC && this.inputSWF != null && this.inputSWF != "null" && this.inputSWF != "" ? DYNAMIC : NORMAL);
  138.       }
  139.       
  140.       public function set settings(settings:Settings) : void
  141.       {
  142.          this.inputSWF = settings.inputSWF;
  143.          this.mouseUpComplete = settings.mouseUpComplete;
  144.          if(settings.type == ELASTIC && this.type != ELASTIC)
  145.          {
  146.             this.mouseUpComplete = this.elasticMouseUpComplete;
  147.          }
  148.          else if(settings.type != ELASTIC && this.type == ELASTIC)
  149.          {
  150.             this.elasticMouseUpComplete = this.mouseUpComplete;
  151.          }
  152.          if(settings.type != DYNAMIC && this.type == DYNAMIC)
  153.          {
  154.             this.unloadInputSWF();
  155.          }
  156.          else if(settings.type == DYNAMIC && this.type != DYNAMIC)
  157.          {
  158.             this.mouseUpComplete = true;
  159.          }
  160.          this.type = settings.type;
  161.          if(this.type == DYNAMIC)
  162.          {
  163.             this.loadInputSWF();
  164.          }
  165.          this.lockMouse = settings.lockMouse;
  166.          this.elastic = settings.elastic;
  167.          this.friction = settings.friction;
  168.          this.minDrawSpeed = settings.minDrawSpeed;
  169.          this.maxDrawSpeed = settings.maxDrawSpeed;
  170.          this.smoothing = settings.smoothing;
  171.       }
  172.       
  173.       public function setDynamicInput(path:String) : void
  174.       {
  175.          this.inputSWF = path;
  176.          this.type = DYNAMIC;
  177.       }
  178.       
  179.       public function get lockMouse() : Boolean
  180.       {
  181.          return this.type == DYNAMIC ? this._lockMouse : false;
  182.       }
  183.       
  184.       public function setXML(xml:String) : void
  185.       {
  186.          var element:XML = null;
  187.          var drawSpeed:Array = null;
  188.          var lineXML:XML = new XML(xml);
  189.          for each(element in lineXML.*)
  190.          {
  191.             try
  192.             {
  193.                if(element.name() == "drawSpeed")
  194.                {
  195.                   drawSpeed = element.toString().split(",");
  196.                   this.minDrawSpeed = drawSpeed[0];
  197.                   this.maxDrawSpeed = drawSpeed[1];
  198.                }
  199.                else if(element.name() == "smoothing")
  200.                {
  201.                   this.smoothing = element == "true" ? true : false;
  202.                }
  203.                else if(element.name() == "mouseUpComplete")
  204.                {
  205.                   this.mouseUpComplete = element == "true" ? true : false;
  206.                }
  207.                else
  208.                {
  209.                   this[element.name()] = element;
  210.                }
  211.             }
  212.             catch(e:Error)
  213.             {
  214.             }
  215.          }
  216.       }
  217.       
  218.       public function clone(style:Style) : LineStyle
  219.       {
  220.          var lineStyle:LineStyle = new LineStyle(style);
  221.          lineStyle.settings = this.settings;
  222.          return lineStyle;
  223.       }
  224.       
  225.       public function getXML() : XML
  226.       {
  227.          var lineXML:XML = new XML(<line/>);
  228.          lineXML.appendChild(<type>{this.type}</type>);
  229.          lineXML.appendChild(<inputSWF>{this.type == DYNAMIC ? this.inputSWF : ""}</inputSWF>);
  230.          lineXML.appendChild(<elastic>{this.elastic}</elastic>);
  231.          lineXML.appendChild(<friction>{this.friction}</friction>);
  232.          lineXML.appendChild(<drawSpeed>{this.minDrawSpeed + "," + this.maxDrawSpeed}</drawSpeed>);
  233.          lineXML.appendChild(<smoothing>{this.smoothing}</smoothing>);
  234.          lineXML.appendChild(<mouseUpComplete>{this.mouseUpComplete}</mouseUpComplete>);
  235.          return lineXML;
  236.       }
  237.       
  238.       public function loadInputSWF() : void
  239.       {
  240.          if(this.inputLoader != null)
  241.          {
  242.             this.unloadInputSWF();
  243.          }
  244.          this.inputLoader = FileManager.getInstance().loadInputSWF(this.inputSWF,this.inputSWFLoaded,this.loadErrorHandler);
  245.       }
  246.       
  247.       public function set mouseUpComplete(b:Boolean) : void
  248.       {
  249.          this._mouseUpComplete = b;
  250.       }
  251.       
  252.       public function unloadInputSWF() : void
  253.       {
  254.          try
  255.          {
  256.             this.inputLoader.unload();
  257.             this.inputLoader = null;
  258.          }
  259.          catch(e:Error)
  260.          {
  261.          }
  262.       }
  263.       
  264.       public function get mouseUpComplete() : Boolean
  265.       {
  266.          return this.type == DYNAMIC && !this._mouseUpComplete ? false : this._mouseUpComplete;
  267.       }
  268.       
  269.       public function set lockMouse(b:Boolean) : void
  270.       {
  271.          this._lockMouse = b;
  272.       }
  273.    }
  274. }
  275.  
  276.