27Aug

Flash Back!

No comments

So I started to work on a project for friend of mine, she is really into designer handmade knits and clothes, anyways, while I was digging through some archived files, I came across this game.. which I never finished.. but it was one of my favorites - built with Flash MX.

You can check out my diving game here - just click the jump button when the skeleton is moving fast

Share/Save/Bookmark

Categories: Web Development
26Aug

Google Analytics and AIR

No comments

So I thought I would take my old post of finding the median value of my Google Analytics and convert this to an Adobe AIR application. Here is the old post.

Here is the code I am beginning with:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="800" height="800">
<mx:Script>
<![CDATA[
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
import mx.controls.Alert;
import MedianGraph;

private function loadGA():void
{
if ( !loc.text || loc.text == "Enter Location of XML File")
{
Alert.show ("Please enter location of your Google Analytics file", "ERROR");
}
else
{
// read the file
var myFile:File = File.documentsDirectory.resolvePath( loc.text );
var fileStream:FileStream = new FileStream();
fileStream.open(myFile, FileMode.READ);

var xml:XML = new XML(fileStream.readUTFBytes(fileStream.bytesAvailable));

var pointList:XMLList = xml.Report.Graph[0].Serie.Point.Value.text();
var timeList:XMLList = xml.Report.Graph[0].Serie.Point.Label.text();

var xPoint:Array = new Array;

for each (var graphPoints:XML in pointList)
{
xPoint.push( graphPoints );
}

var tPoint:Array = new Array;

for each (var timePoints:XML in timeList)
{
tPoint.push ( timePoints );
}

var graphArray:Array = new Array;
for (var c:uint; c < xPoint.length; c++){
graphArray.push ({point:xPoint[c], time:tPoint[c]})
}

// sort the array from lowest to highest
var medianArray:Array = new Array();
medianArray = graphArray.sortOn("point", Array.NUMERIC);

// check to see if there is an even or odd numbers in the list
var evenOdd:uint = medianArray.length%2;
var medianArrIndex:Number;

if ( evenOdd == 1 )
{
/* odd number */
/* take the middle value */
medianArrIndex = medianArray[Math.floor(medianArray.length / 2)].point;
}
else
{
/* even number */
/* take the 2 middle numbers, add them together and divide by 2 */
var middle:Number = medianArray.length / 2;

var lowMiddle:Number = medianArray[middle - 1].point;
var highMiddle:Number = medianArray[middle].point;
medianArrIndex = (highMiddle + lowMiddle) / 2;

var medianPoint:Array = new Array();

/* ——————————————- */
for (var x:uint; x < medianArray.length; x++)
{
medianPoint.push ({point:medianArrIndex, time:tPoint[x]})
}
/* ——————————————- */
}

Alert.show ("The median point is: " + medianArrIndex);
fileStream.close();
}
}

private function browseForOpen():void
{
var file:File = new File();
file.addEventListener(Event.SELECT, openHandler);
file.browseForOpen("Select a File");
}

private function openHandler(e:Event):void
{
loc.text = e.target.nativePath;
}
]]>
</mx:Script>
<mx:TextInput text="Enter Location of XML File" width="500" x="10" y="3" id="loc" enter="loadGA()" />
<mx:Button click="browseForOpen()" label="Browse for File" x="511" y="3" />
<mx:Button click="loadGA()" label="GO!" x="650" y="3" />
</mx:WindowedApplication>

Share/Save/Bookmark

Categories: AIR, Actionscript 3
25Aug

Adobe AIR - Select A File

No comments

A simple method to allow the user to select a local file:




	
	
	

Share/Save/Bookmark

Categories: AIR
22Aug

Trails Animation - Version 2

No comments

A new trails animation with a blur effect and a motion of the objects animated towards you. Please note: This is a work in progress and the Main.as file needs to be cleaned up so there aren’t 2 entries for the image load when the movie clip is duplicated.

package
{
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	 public class Main extends MovieClip
	 {
		private var clip_arr:Array; // an array of clips
		private var clip_ct:Number = 0;

		private const RADIUS:int=30;
		private const FRICTION:Number=.95;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			stage.frameRate=31;

			clip_arr = new Array();

			var myTimer:Timer = new Timer(5000, 10);
            myTimer.addEventListener("timer", createClip);
            myTimer.start();
		}

		private function createClip(e:TimerEvent):void
		{
			var randXOffset = Math.random() * stage.stageWidth;
			var randYOffset = Math.random() * stage.stageHeight;

			clip_arr.push ( new Image("smiley.png") );

			clip_arr[clip_ct].scaleX = clip_arr[clip_ct].scaleY = 0;
			clip_arr[clip_ct].x=Math.cos(clip_arr[clip_ct].angle*1)*RADIUS + randXOffset;
			clip_arr[clip_ct].y=Math.sin(clip_arr[clip_ct].angle*2)*RADIUS + randYOffset;
			clip_arr[clip_ct].offsetX = randXOffset;
			clip_arr[clip_ct].offsetY = randYOffset;
			clip_arr[clip_ct].angle=0;
			addChild(clip_arr[clip_ct]);

			clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,go);
			clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,cleanUp);

			clip_ct++;
		}

		private function go(evt:Event):void
		{
			evt.target.scaleX += .05;
			evt.target.scaleY += .05;

  			evt.target.x=Math.cos(evt.target.angle*2)*RADIUS + evt.target.offsetX;
  			evt.target.y=Math.sin(evt.target.angle*3)*RADIUS + evt.target.offsetY;
  			evt.target.angle+=.05;

			var copy_mc:MovieClip = new Image(”smiley.png”);
  			addChild(copy_mc);

			copy_mc.scaleX = evt.target.scaleX;
			copy_mc.scaleY = evt.target.scaleY;
  			copy_mc.x=evt.target.x;
  			copy_mc.y=evt.target.y;
 			copy_mc.addEventListener(Event.ENTER_FRAME,goCopy);

		}

		private function goCopy(evt:Event):void
		{
			evt.target.alpha*=FRICTION;

			var blurRate = Math.floor(Math.abs((evt.target.x - stage.stageWidth/2) / 100) * 2);
            evt.target.blurImage(blurRate,blurRate);

			if(evt.target.alpha<=.3)
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,goCopy);
				var m:MovieClip=evt.target as MovieClip;
				removeChild(m);
			}
		}

		private function cleanUp(evt:Event):void
		{
			if ( evt.target.scaleX >= 3 )
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,go);
				evt.target.removeEventListener(Event.ENTER_FRAME,cleanUp);

				var d:DisplayObject=evt.target as DisplayObject;
				removeChild(d);
			}
		}
	}
}

a class to load in the image, although if you use this code you should add in a listener to make sure the image is loaded prior to implementing it

package
{
	import flash.display.MovieClip;
	import flash.display.Loader;
    import flash.display.LoaderInfo;
	import flash.net.URLLoader;
    import flash.net.URLRequest;
	import flash.filters.BitmapFilterQuality;
    import flash.filters.BlurFilter;

	public class Image extends MovieClip
	{
		// public properties for the class
		public var earl:String;

		public var angle = Number;
		public var offsetX = Number;
		public var offsetY = Number;

		public var imgLoader:Loader = new Loader();

		private var blur:BlurFilter = new BlurFilter();

		public function Image(e:String)
		{
			earl = e;

			// Load in the image
            var imgLoader:Loader = new Loader();
            imgLoader.load(new URLRequest(earl));

			// add image loader
            addChild(imgLoader);

		}

		public function blurImage(blurX:Number=0, blurY:Number=0)
		{
			blur.quality = BitmapFilterQuality.MEDIUM;
            blur.blurX = blurX;
            blur.blurY = blurY;

			this.filters = [blur];
		}
	}
}

Share/Save/Bookmark

Categories: Actionscript 3
21Aug

Trails Animation

No comments

This code was submitted to me via email who requested some assistance to get this trailing animation to be bound by any newly created object. I edited the code slightly and added a Rect class to build my rectangle object (which could be replaced by an image if so desired). I added a timer to reproduce the object, here is the resulting code/movie:

The Main.as:

package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	 public class Main extends MovieClip
	 {
		private var clip_arr:Array; // an array of clips
		private var clip_ct:Number = 0;

		private var clip_mc:Rect;

		private const RADIUS:int=30;
		private const FRICTION:Number=.95;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			stage.frameRate=31;

			clip_arr = new Array();

			var myTimer:Timer = new Timer(500, 50);
            myTimer.addEventListener("timer", createClip);
            myTimer.start();
		}

		private function createClip(e:TimerEvent):void
		{
			var randXOffset = Math.random() * stage.stageWidth;
			var randYOffset = Math.random() * stage.stageHeight;

			clip_arr.push ( new Rect() );
			clip_arr[clip_ct].x=Math.cos(clip_arr[clip_ct].angle*1)*RADIUS + randXOffset;
			clip_arr[clip_ct].y=Math.sin(clip_arr[clip_ct].angle*2)*RADIUS + randYOffset;
			clip_arr[clip_ct].offsetX = randXOffset;
			clip_arr[clip_ct].offsetY = randYOffset;
			clip_arr[clip_ct].angle=0;
			addChild(clip_arr[clip_ct]);
			clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,go);

			clip_ct++;
		}

		private function go(evt:Event):void
		{
  			evt.target.x=Math.cos(evt.target.angle*2)*RADIUS + evt.target.offsetX;
  			evt.target.y=Math.sin(evt.target.angle*3)*RADIUS + evt.target.offsetY;
  			evt.target.angle+=.05;

  			var copy_mc:MovieClip=new Rect();
  			addChild(copy_mc);

  			copy_mc.x=evt.target.x;
  			copy_mc.y=evt.target.y;
 			copy_mc.addEventListener(Event.ENTER_FRAME,goCopy);
		}

		private function goCopy(evt:Event):void
		{
			evt.target.alpha*=FRICTION;
			evt.target.scaleY=evt.target.alpha;
			if(evt.target.alpha<=.3)
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,goCopy);
				var m:MovieClip=evt.target as MovieClip;
				removeChild(m);
			}
		}
	}
}

The rect class:

package
{
	import flash.display.MovieClip;

	public class Rect extends MovieClip
	{
		private var xPos:Number;
		private var yPos:Number;
		private var rWidth:Number;
		private var rHeight:Number;
		private var color:uint;

		public var angle = Number;
		public var offsetX = Number;
		public var offsetY = Number;

		public function Rect(xPos:Number=0,yPos:Number=0,rWidth:Number=10,rHeight:Number=10,color:uint=0x336699)
		{
			this.graphics.beginFill(color);
			this.graphics.drawRect(xPos,yPos,rWidth,rHeight);
			this.graphics.endFill();

			this.angle = 0;
		}
	}
}

Share/Save/Bookmark