Examples

Primative Pong Game
Primative Black Jack Game
Basic OO Black Jack Game
Basic Form
Complex Form
JavaScript from ActionScript
Basic Image Animation
Hello World on a Timer
Tads Basic Checker Class
A Simple FLV Player
Simple getter use
A liaison Class
Parent Child Control
Wrapper to server bridge
Primative Space Shooter Game
Simple XML Loader
Primative Speed Simulation
Simple Sound Mixing
A Simple Color Picker
 



/* This package simply puts a PickAColour instance on its display. 
   It is used to make the color picker bigger for this example.    */

/* PickAColour.as is in the same folder as this class (showAColourPicker) during compile time, 
   so this class can just initiate a new PickAColour without any import or embed.  
 (It gets automatically imported in during compile time, you do not need PickAColour.as to run the compiled SWF) */

package
{

 import flash.display.Sprite;


 public class showAColourPicker extends Sprite  
 {


    public function showAColourPicker() 
    {

    	var aPicker:Sprite = new PickAColour();
    	aPicker.scaleX *= 3;
	aPicker.scaleY *= 3;
	addChild(aPicker);

    }


 }

}

/* This is the color picker named PickAColour.as  that gets used above to produce this example. */

/* This example does not do anything but show a color picker, the class on its own, is just a color picker.
   To make use of it, some other class will need to reference objects in here, (particularly, Sprite names)
   
   To see the colour picker in use go to the Js In ActionScript example; 
   there you can change the colour of the site with the help of this PickAColour Class. */


package
{

  import flash.display.Sprite;
  import flash.display.Graphics;
  import flash.events.MouseEvent;
  import flash.geom.Transform;
  import flash.geom.ColorTransform;
  import flash.text.TextField;


  public class PickAColour extends Sprite 
  {

    private var greenHexs:Array;
    private var blueHexs:Array;
    private var redHexs:Array;

    private var greenRGBs:Array;
    private var redRGBs:Array;
    private var blueRGBs:Array;
    private var aquaRGBs:Array;
    private var yellowRGBs:Array;


    public function PickAColour() 
    {


  	greenHexs = 
  	[ "00FF00", "00DD00", "00BB00", "009900", "007700", 
    	 "005500", "003300", "001100", "441144", "44BB44", "44DD44", "44FF44" ];


  	blueHexs = 
  	[ "0000FF", "0000DD", "0000BB", "000099", "000077", "000055", "000033", 
    	 "000011", "444411", "4444BB", "4444DD", "4444FF" ];


  	redHexs = 
  	[ "FF0000", "DD0000", "BB0000", "990000", "770000", "550000", "330000", 
    	 "110000", "114444", "BB4444", "DD4444", "FF4444"  ];

  	greenRGBs = [];
  	generateRGBColors(greenRGBs, [0,1,0]);
  	blueRGBs = [];
  	generateRGBColors(blueRGBs, [0,0,1]);
  	redRGBs = [];
  	generateRGBColors(redRGBs, [1,0,0]);
  	yellowRGBs = [];
  	generateRGBColors(yellowRGBs, [1,1,0]);
  	aquaRGBs = [];
  	generateRGBColors(aquaRGBs, [0,1,1]);

  	setUpPicker();


    }


private function generateRGBColors(theArray:Array, pattern:Array):void 
{

  for (var i:int = 255; i>8; i-=8)
  {
	var toPut:Array = [ pattern[0]*i,pattern[1]*i,pattern[2]*i ];
	(theArray) ? theArray.push(toPut) : theArray = [ toPut ];
  }

}


private function setUpPicker():void 
{

      	hexBoxCreationFor(blueHexs, 30);
      	hexBoxCreationFor(greenHexs, 15);
      	hexBoxCreationFor(redHexs);

      	rgbBoxCreationFor(blueRGBs, 55);
      	rgbBoxCreationFor(greenRGBs, 65);
      	rgbBoxCreationFor(redRGBs, 75);
      	rgbBoxCreationFor(yellowRGBs, 85);
      	rgbBoxCreationFor(aquaRGBs, 95);
  

}


private function rgbBoxCreationFor(thisRGBArray:Array, xPosition:Number = 0):void 
{


  for (var rsi:int = 0; rsi < thisRGBArray.length; rsi ++) 
  {

	var aSmallBox:Sprite = new Sprite();
	aSmallBox.graphics.beginFill(0x000000);
	aSmallBox.graphics.drawRect(0,0,3.85,3.85);
	aSmallBox.transform.colorTransform =  
        new ColorTransform(0, 0, 0, 1, thisRGBArray[rsi][0], thisRGBArray[rsi][1], thisRGBArray[rsi][2], 0);
	aSmallBox.y = xPosition;
	aSmallBox.x = rsi*3.85;
	aSmallBox.name = ""+thisRGBArray[rsi][0]+","+thisRGBArray[rsi][1]+","+thisRGBArray[rsi][2]+"";
	aSmallBox.addEventListener(MouseEvent.MOUSE_OVER, showMeMore);
	aSmallBox.addEventListener(MouseEvent.MOUSE_OUT, showMeLess);
	aSmallBox.addEventListener(MouseEvent.CLICK, showJustMe);
	addChild(aSmallBox);

  }




}


private function hexBoxCreationFor(thisHexArray:Array, xPosition:Number = 0):void 
{


  for (var si:int = 0; si<thisHexArray.length; si++) 
  {

	var aBox:Sprite = new Sprite();
	aBox.graphics.beginFill(uint("0x"+thisHexArray[si]));
	aBox.graphics.drawRect(0,0,10,10);
	aBox.y = xPosition;
	aBox.name = thisHexArray[si].toString();
	aBox.x = si*10;
	aBox.addEventListener(MouseEvent.MOUSE_OVER, showMeMore);
	aBox.addEventListener(MouseEvent.MOUSE_OUT, showMeLess);
	aBox.addEventListener(MouseEvent.CLICK, showJustMe);
	addChild(aBox);

  }

}



private function showMeMore(e:MouseEvent):void 
{
	e.target.scaleX = e.target.scaleY *= 1.2;
}

private function showMeLess(e:MouseEvent):void 
{
	e.target.scaleX = e.target.scaleY = 1;
}

private function showJustMe(e:MouseEvent):void 
{

/* Instead of setting up event dispatchers, what do we know?
   That the box sprite selected will have the greatest scale (of its kind) and its name is the color value */


  for (var i:int = 0; i < numChildren; i++) 
  { 
  	var theChild:Sprite = getChildAt(i) as Sprite;theChild.scaleX = theChild.scaleY = 1;
        if (!theChild.hasEventListener(MouseEvent.MOUSE_OUT)) 
	{theChild.addEventListener(MouseEvent.MOUSE_OUT, showMeLess);
	theChild.addEventListener(MouseEvent.MOUSE_OVER, showMeMore);}
  }

  	e.target.scaleX = e.target.scaleY *= 1.2;
	e.target.removeEventListener(MouseEvent.MOUSE_OUT, showMeLess);
	e.target.removeEventListener(MouseEvent.MOUSE_OVER, showMeMore);

}


 }
}



Compiled Result: