Archive for the “ActionScript 3” Category


If you use Photoshop you probably appreciate the "Constrain Proportions" checkbox found in some of the application's dialogs and menus.

I like to have this same ability when I'm writing ActionScript to resize objects proportionately too.
Here I use the functions to set the sizes so when I set width, height is changed accordingly.
The same for setting height, the width is changed accordingly.

*Note: I set the inputs to limit the width and height to 500.

Here are two functions for performing proportional resizing by both width and height...
Read the rest of this entry »

Comments No Comments »

This Actionscript 3 function returns some properties that are about a line-to-polygon intersection.
It's useful for knowing all intersection points of a segment intersecting with a polygon, and knowing if the end points of the segment are inside the polygon.

Read the rest of this entry »

Comments No Comments »

Here is an ActionScript 3 function that will return intersection information between a segment and circle.
It's useful to me to know if a segment is partially intersecting with a circle or going completely through.


Read the rest of this entry »

Comments 1 Comment »

The intersection Point of two lines is useful to know. This is a function to find it in AS3.


Read the rest of this entry »

Comments 2 Comments »

Here is a Flex UI component I've been writing. Click the image to play with what I have made so far.
You can change a variety of properties. The dial and mark are runtime skinnable by setting its "dialBackgroundSkin" or "dialMarkSkin" property to a url with an image. 

Knobs and dials just look cool...I don't know anything about audio editing but I like the site of a sound studio. This is the "Reason" I decided to make a knob component.

Nice Knobs

Comments 1 Comment »

Here is a scrolling background and keyboard control test for some AS3 classes I been working on. I used the image of superman from some sprite graphics I found on the web. The images for his flight positions are loaded dynamically. This is for allowing me to load other images for different characters without changing too much script.

Superman Flash test

Comments No Comments »

The XML examples represent a book in a library. However the book has several bookworms in it.
Using E4X we can find these bookworms.

 
<library>
	<book>
<page id="one"/>
		<worm name="Eddy" />
<page id="two"/>
<page id="three">
			<worm name="Lisa"/>
			<worm name="Pete" />
		</page>
<page id="four"/>
	</book>
</library>
 

There are some E4X operators and XML methods to help use do this when combined together:

.. Access all descendants of the XML object.
. Access a property of an Object or XML.
* Wildcard, match any part of the XML.
childIndex() Index number of an XML object relative to its parent node.
name() Name of the XML node.

Read the rest of this entry »

Comments No Comments »

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 »

Comments No 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;
      }
 

Comments No Comments »

Thanks for visiting www.keith-hair.net