Archive for May 30th, 2008

You ever wanted an Object to move along the path of a curve?...a curve drawn with the ActionScript drawing API.

The curves drawn using the API are quadratic. Using the following expressions, you can plot an "x" or "y" value on a curve at a time between 0 - 1. You could even plot a "z" value for 3D if you wanted.

var x:Number=Math.pow(1-time,2)*startvalueX+2*(1-time)*time*controlX+Math.pow(time,2)*endvalueX;
var y:Number=Math.pow(1-time,2)*startvalueY+2*(1-time)*time*controlY+Math.pow(time,2)*endvalueY;


Read the rest of this entry »

Vote in HexoSearch

Comments 5 Comments »

These are some functions I wrote for finding and replacing parts of XML using AS3.
Not sure if E4X or "XML.replace()" method can be used to make each function's task better.

 
/*-----------------------------------
	Recursively replace nodeNames.
-------------------------------------*/
      private function findAndReplaceTagNames
      (xml:XML,find:String,replace:String):XML
      {
          if(xml.localName() == find){
              xml.setLocalName(replace);
          }
          var n:int=0;
          var c:XML;
          while(n <xml.children().length()){
              c=xml.children()[n];
              findAndReplaceTagNames(c,find,replace);
              n++;
          }
          return xml;
      }
 
/*-----------------------------------------
	Recursively replace attributes.
-------------------------------------------*/
      private function findAndReplaceAttributeNames
      (xml:XML,find:String,replace:String,in_tags_named:String=""):XML
      {
          var ok:Boolean=true;
          if(in_tags_named != "" && xml.localName() != in_tags_named){
              ok=false;
          }
          if(xml.@[find] != null && ok){
              xml.@[replace]=xml.@[find];
              delete xml.@[find];
          }
          var n:int=0;
          var c:XML;
          while(n <xml.children().length()){
              c=xml.children()[n];
              findAndReplaceAttributeNames(c,find,replace);
              n++;
          }
          return xml;
      }
 
/*---------------------------------------------
	Recursively find and remove attributes.
-----------------------------------------------*/
      private function findAndRemoveAttributeNames
      (xml:XML,find:String,in_tags_named:String=""):XML
      {
          var ok:Boolean=true;
          if(in_tags_named != "" && xml.localName() != in_tags_named){
              ok=false;
          }
          if(xml.@[find] != null && ok){
              delete xml.@[find];
          }
          var n:int=0;
          var c:XML;
          while(n <xml.children().length()){
              c=xml.children()[n];
              findAndRemoveAttributeNames(c,find);
              n++;
          }
          return xml;
      }
 
Vote in HexoSearch

Comments 2 Comments »

Thanks for visiting www.keith-hair.net