Shepard Fairy On His “Hope” Poster

So Shepard Fairy is the dude over at Obey Giant that was responsible for the now infamous “Hope” poster of President Obama. For you kiddies who didn’t know, he’s been around the block a few times. Literally, that is. He’s been arrested a few times for his street art. The Obama poster is just a major push into mainstream popularity.

Anyways, here’s a YouTube of him talking about designing the poster.

Posted in Industry News, Misc. | Tagged , , , | 2 Comments

How to Scale in Flash (Bitmap Smoothing)

I apologize to my neglected readers. I’ve been busy lately with a new puppy, and finding a new house. Plus, this stagnant air in Salt Lake City is killing me. But, I’m done making excuses so let’s talk about bitmap smoothing and scaling. I also have some questions for any ActionScript gurus out there that might be able to help.

Flash has some pretty sweet features that we can take advantage of. One of them revolves around the bitmap and bitmap data classes. Let’s say you are creating a photo album and wish to use Flash to accomplish the task. Let’s also say that at some point you are going to have a large image for viewing, but you’ll also want some thumbnails to help in navigating through all your photos.

Assume you have 200 photos that you want to show to the world. One way of going about creating thumbnails would be to setup an action in Photoshop that would take care of the resizing. Hey, it gets the job done, but it’s not sexy and requires the additional file size of all the thumbnails. If you’re familiar with PHP and GD, you could write a script that creates thumbnails on the fly, but that requires you know another language. I say we just do it with ActionScript.

The Basics

Scaling our thumbnails is not really that hard once you understand the concept. Here is what we want to do:

  • Dynamically import our images from a folder on our server
  • Take the bitmap data from that image and cast it as a bitmap
  • Scale down the original image into a thumbnail
  • Apply smoothing to achieve a clean, non-pixelated look

Importing our images

I’ll briefly show some code on how to import the images off your server, but this isn’t the focus of this tutorial so I haven’t built in any fancy preloaders or other user feedback. You may want to do so in your final implementation.

The first thing we’ll do it create a method that starts the loading process. We’ll pass in the URL (a string) to the method so it knows where to grab the image from.

private function startLoad(_loc:String):void {

	//Instantiate the loader (I've defined this outside of the method for global
	//use within the class
	_loader = new Loader();
	_loaderInfo = _loader.contentLoaderInfo;

	//Add a listener that will do some shizzle when the picture is all loaded
	_loaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);

        try {
            	_loader.load(new URLRequest(_loc));
        } catch (err:Error) {
                trace("Unable to load content:\n" + err.message);
        }

}

This starts our picture loading. Once it’s all loaded it will start the onComplete method, which will begin the hard work. Here is that method.

private function onComplete(evt:Event):void {

	//Be a good boy and remove your listener
	_loaderInfo.removeEventListener(Event.COMPLETE, onComplete);

	//Create a sprite to hold our large (unscaled) image
	var _main:Sprite = new Sprite();

	//Copy the pixel data and cast as a bitmap (we could also just add the loader
	//to accomplish the same thing
	var _unscaled:Bitmap = new Bitmap(_loader.getChildAt(0).bitmapData);

	//Put the bitmap in the sprite
	_main.addChild(_unscaled);

	//Add the sprite to the display list
	addChild(_main);

	//Create a new sprite to hold our thumbnail
	var _thumb:Sprite = new Sprite();

	//Move it underneath (or some place else out of the way)
	_thumb.y = 600;

	//Copy the bitmap data of the large image again
	var _scaled:Bitmap = new Bitmap(_loader.getChildAt(0).bitmapData);

	//Scale the bitmap
	_scaled.scaleX = _scaled.scaleY = .25;

	//Apply the smoothing
	_scaled.smoothing = true;

	//Add scaled bitmap to the sprite
	_thumb.addChild(_scaled);

	//Add the sprite to the display list
	addChild(_thumb);

}

Okay, so what did we do here? We created two container sprites that hold the bitmap object. Think of the bitmap we’ve created as a screenshot of the larger image. It provides us with the actual color and location of each pixel. We want to put it into a sprite to allow us to treat it like a button in the future. You can’t attach listeners to bitmap objects.

The only thing left to do is to run the method. It might look something like this.

startLoad('somefolder/image.jpg');

This should get the ball rolling. The above snippets of code aren’t everything you need. If you are writing this in the document class or some other external class you’ll need to import the proper classes. Let me know if you need any help on that, but I’m assuming you probably know what to do.

Stage quality

I consider this part to be the bummer. If you’ve followed through and tested your movie you are probably saying, “That thumbnail looks like ass.” And it really does. It probably looks jagged and crummy. Up until this point, the only way I’ve figured out how to fix this is to set the stage quality to BEST. You can do it like so.

//Make sure to place this in the constructor method of your doc class.
stage.quality = StageQuality.BEST;

Now, if you had chosen to scale the image up instead of down. It would look pretty darn good. You wouldn’t need to change the stage quality at all. To me this is the end goal, because I would rather not take the performance hit from setting the quality to best.

My question to you guys

I would really love to know how others are choosing to do this. Especially if you’ve figured out a way to scale down without having to change the stage quality. Just shoot me an email, tweet, or comment so that I can let others know the goodness that is bitmap smoothing. I’m pretty sure there’s a way, but I just haven’t figured it out yet. The above works, but just make sure your users can deal with extra processing crunch.

Posted in Flash/AS, Flash/ActionScript, Tutorials | Tagged , , , , , | 2 Comments

Craigslist Website Requests Rant

I am a web designer that doesn’t have enough time to code at the moment so I need to outsource a wordpress project.
Yup, you’re a designer alright. You probably have some sweet drop shadows (default lighting) and a bunch of embossed crap. And when you’re feeling really fancy you make everything glossy! You don’t have time to code? Phhh…too busy being a designer for that. You also don’t know how and are just accustomed to downloading free themes.

I need to clone a theme that looks like the following: (link to a theme that was months in development with thousands of dollars spent)

Don’t worry, I’ll just fire up Frontpage and get that finished for you. It probably only took those developers a couple minutes, so I should have it done in no time. I’ll even make sure I support Opera, Chrome, Camino, and IE 5.5 because I’m hardcore like that.
I have PSD’s of the design which differs a bit, but the functionality will remain nearly the same.

Really! Oh boy. Can I cut them up for you? Do I have to fix all the eventual png transparency issues in IE6 or can I just leave the retarded light blue box? Oh, and let’s face it. You changed some colors, but are basically just ripping off someones hard work.

Please send me a link to some online examples of your work and also give me a quote as to what it would take.

Yay. I’ll send you my portfolio so you can steal from it too. And before we discuss anyting at all I’ll just whip up a quote based on this other guys site you linked too. We won’t discuss target market, goals for the site, SEO. Nope. I’ll just throw a dart at my “quote board” and send you whatever it lands on.

Budget: $50-$500

I’m gonna be rich! I better not ask for too much because other people might under-bid me. This probably won’t take that long. Plus, my billable rate is, like, $10/hr. I think I’ll come out ahead.

Quick, I better email them back.

Posted in Misc., Web Design | Tagged , , , | Leave a comment

Error #2136: The SWF file (swfURL.swf) contains invalid data. at (parent class)

A user submitted question here. He was wondering why he kept getting this error when trying to extend a parent or a super class. I figure I might as well let everyone know the answer. Let me first describe what was going on.

The Situation

I’ll strip out all the non essential code, but he basically had a subclass that was extending the parent class. Nothing too complicated at this point. The problem really arose when he tried to instantiate the subclass in his parent class. Do you see what’s wrong with this picture? Yup, an infinite loop.

When you extend a parent class, you are effectively running it’s constructor function and defining any variables in the parent class. So if you are calling a subclass from the parent class you’re going to end up with an infinite loop and thus the #2136 error.

This boils down to the OOP theories of inheritance and composition. This particular reader was aiming at more of a compositional model rather than inheritance. Google those two OOP terms if you are interested in finding out more about them.

The example code (this is wrong)

//The parent class
package {

	import flash.display.MovieClip;

	public class Parent extends MovieClip {
		public function Parent() {
			var _child:Child = new Child();
		}
	}
}
//Child class
package {

	import flash.display.MovieClip;

	public class Child extends Parent {
		public function Child() {
			trace("Why in the heck doesn't this work?");
		}
	}
}

The above too classes was the gist of what he was doing. You can hopefully see the problem right away. Hopefully this helps someone who gets stuck on this!

Posted in Flash/ActionScript | Tagged , , , | 2 Comments

Full Browser Flash With Centered Content Using Swfobject (AS3)

This particular technique is not new by any means, but it is nice method of going full browser. By full browser I mean the entire viewing area of FireFox, Safari, IE, or whatever you view your web pages in. The method also uses swfobject to deploy your Flash content. If you’re not familiar with swfobject, view my previous post here. In summary, swfobject is now going to be the de-facto standard in Flash embedding. Adobe is now using it as their default embedding option in Dreamweaver CS4. In other words, it’s completely legit and something you should really get used to.

The Goal

I want to be clear on what we are trying to accomplish here and what technologies we are using. A quick Google search on any of these topics will yield a crap ton of results and not all of them are helpful. You would have to do a lot of piecing together to get what I have here, so don’t bother. Here is what we want to do:

  • Use ActionScript 3 (AS3)
  • Get full browser flash, but not full screen
  • Use Swfobject as our means of Flash deployment
  • Use a swf of static dimensions (eg. 800×600 that doesn’t expand or contract)
  • Center horizontally
  • Center vertically
  • Have the browser display scroll-bars when the browser becomes smaller than the viewing area

If this is exactly what you were looking for then simply continue reading. If you are looking for a variation of this, you may still be able to tweak a couple things to get your desired result. Let’s do this.

Step 1 – Create your Flash file

Go ahead and open up Flash. Go into your document properties (command+J, or control+J) and make the document dimensions 800 x 600. Set your background color to black, #000000. You’re settings should look like this:

Document Properties

Document Properties

After you do that, go ahead and drag ruler guides in 50px from every side. This will give you a guide to draw out a rectangle that will act as your content area. Select the rectangle tool and draw out your rectangle within the new guides. I changed the fill to a bitchin’ blue gradient! Here is what you should now have:

Totally sweet blue radial gradient

Totally sweet blue radial gradient

Step 2 – The ActionScript

Now we need to go ahead and add our ActionScript. I prefer to enter everything into Document Classes, but you could just as easily add this to the first frame of your fla file.

package {

	//For Display
	import flash.display.*;

	//For Events
    import flash.events.*;

	public class FullScreen extends MovieClip {

		public function FullScreen() {

			//This ensures that your flash content won't expand
			//if the user expands the browser window.
			stage.scaleMode = StageScaleMode.NO_SCALE;

			//Listen for resizing
			stage.addEventListener(Event.RESIZE, resizeHandler);

		}

		private function resizeHandler(event:Event):void {
			/*
			In this method you could choose to put specific instructions
			telling certain display elements where they should be aligned.
			For instance, you have a nav bar that you always want to be
			20px from the top. You could do that here.
			*/

		}

	}

}

Step 3 – Use Swfobject to generate our html file

I previously wrote an article explaining how to deploy your Flash content using swfobject. If you aren’t familiar with swfobject you should go read it.

You can go ahead and generate your html file like my previous tutorial says to get started. But we are going to have to swap out some code to achieve our desired results. Either open up your generated html file, or just start with a blank one and paste in the following code. This is the entirety of the html document so as not to leave any confusion.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

		<link href="site.css" rel="stylesheet" type="text/css" />
			<script type="text/javascript" src="swfobject.js"></script>
			<script type="text/javascript">
				var flashvars = {};
				var params = {};
				params.scale = "noscale";
				var attributes = {};
				swfobject.embedSWF("FullScreen.swf", "flash", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
			</script>

			<script type="text/javascript">
			//<![CDATA[
			function getViewportSize() {
				var size = [0, 0];
				if (typeof window.innerWidth != "undefined") {
					size = [window.innerWidth, window.innerHeight];
				}
				else if (typeof document.documentElement != "undefined" &amp;amp;amp;amp;&amp;amp;amp;amp; typeof document.documentElement.clientWidth != "undefined" &amp;amp;amp;amp;&amp;amp;amp;amp; document.documentElement.clientWidth != 0) {
					size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
				}
				else {
					size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
				}
				return size;
			}
			function createFullBrowserFlash() {
				swfobject.createCSS("html", "height:100%;");
				swfobject.createCSS("body", "height:100%;");
				swfobject.createCSS("#flash", "margin:0; width:100%; height:100%; min-width:700px; min-height:500px;");
				window.onresize = function() {
					var el = document.getElementById("container");
					var size = getViewportSize();
	 				el.style.width = size[0] < 770 ? "700px" : "100%";
					el.style.height = size[1] < 390 ? "500px" : "100%";
				};
				window.onresize();
			}
			swfobject.embedSWF("Preloader.swf", "content", "100%", "100%", "9.0.0");
			if (swfobject.hasFlashPlayerVersion("9.0.0")) {
				swfobject.addDomLoadEvent(createFullBrowserFlash);
			}
			//]]>
			</script>

	</head>
	<body>
		<div id="flash">
			<a href="http://www.adobe.com/go/getflashplayer">
				<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
			</a>
		</div>
	</body>
</html>

You can ignore most of the code. But, you’ll need to pay attention to where we’re telling swfobject that the dimensions of the swf file are 100% vertical and 100% horizontal. This gives us the full browser we are looking for. The other important thing to look at is the javascript dealing with the minimum height and width of our “stage.” I’ve chosen to take into account the 50px padding on all sides of our fla making the height 500px, and the width 700px. I did this because I don’t want scroll bars to appear until there is actual content being covered up.

Don’t worry, we’re almost there. We have one thing left to do, and that is write our CSS.

Step 4 – The CSS

It doesn’t matter if you import your CSS or write it into the header, but it should look like:

body {
	padding:0;
	margin:0;
	background:#000; /*same color as your flash bg */
	text-align:center;
}

#flash {
	margin:0 auto;
	width:700px; /* I only want scroll bars to appear when the window is smaller than the actual content */
	overflow:visible;
	vertical-align:center;
	height:600px;
}

All Done

At this point you should be done! Congrats. You now have a full browser and centered Flash page. Pretty awesome right? Check out the example here.

For those lazy people who want the files

Here they are.

Posted in Flash/AS, Flash/ActionScript, Tutorials | Tagged , , , , | Leave a comment

Flash Deployment with Swfobject

What is Swfobject and why should I care? Answer: if you work in Flash and don’t use it, you’re an idiot. Okay, sorry. I shouldn’t have said that. I’m sure you’re quite special. My mommy told me I was special too! I digress. Swfobject is a way to deploy your Flash content. Simply, it is how you put your swf into an html page. And moving forward, it’s how Adobe is going to do it, which effectively makes it the standard.

What you need

You’ll need a few things before we get started. Swfobject has all their stuff hosted on Google Code. Go here and download the following:

  • swfobject.zip (current version as of this writing is 2.1)
  • swfobject generator (Air version)

There is also an html generator, but it really doesn’t have the full features that the Adobe Air version has. You’ll obviously need Adobe Air installed for it to work. Once downloaded and installed you can go ahead and open up the generator.

The generator looks something like this:

Swfobject's Air application

Swfobject's Air application

First Steps

The first thing you’ll probably want to do is move over the necessary files to your server. Open up the swfobject zip file you just downloaded and move over the following files, expressInstall.swf and swfobject.js to a directory of your choosing. Make note of where you put them, because you’ll be asked later.

Filling out the generator

Here is the list of the fields and what they mean:

  • SWFObject.js – the relative path to this file. It will need to be uploaded to your server.
  • Publishing Method – Static means a simpler (less Javascript) implementation. Dynamic is a little more featured and helps with the IE6 “Click to Activate” bug. My recommendation is to use Dynamic publishing.
  • Detect Flash Version – What is the minimum flash version you require?
  • Adobe Express Install – If checked it will perform the install within your swf, rather than navigating away to Adobe’s site. It’s slick and I’d use it.
  • HTML container id – the name of the div you are using to hold your swf file.
  • Flash (.swf) – the relative path to your swf file.
  • Dimensions – the height and width of your swf.
  • Flash content id – what javascript uses to refer back to the Flash object (you can leave blank)
  • HTML Template – just what type of html you prefer
  • Character encoding – if you know what this is then you know what this is. Leave alone otherwise.
  • Alternative Content – Fill in what you want to display if the user doesn’t have the required Flash version.

I left out all the explanations if you happened to click “more” under SWF definition. There’s a good chance that if you’re getting into this section you probably know what most of them do.

After you’ve appropriately filled out all the fields, you have a couple of options. You can click Generate to get your code. Then copy and paste the code to your html file. Or you can actually click Save File and save it to the location of your choice.

Summary

There are a number of ways to deploy your Flash content, but in my opinion this is the best. It allows you to display alternate content to uses without the proper Flash Player version and then gives them the ability to install it right there. No sending away visitors and not having them come back. If you are a more of a visual person, here is a link to a good video that goes through the same stuff I just went over.

Posted in Flash/ActionScript | Tagged , , , , , | Leave a comment

Freeb – AS3 Reflection Classes

I’ve been working on a reflection class as of late that would semi mirror the 3D OS X dock effect. I started out by implementing a lot of the ideas from Ben Pritchard of Pixelfumes. I had to modify a few things for my own purposes namely placing everything inside a container movie clip for the separate selection of the original movieclip and reflection. In my eventual implementation the movieclips will be serving as buttons, and I didn’t want the reflections part of the hit state.

There are two classes needed to get the below effect. The first is Reflection.as, which is then extended by ReflectionHorizon.as. Here is the example:

An important thing to note is that the class does require the use of a bitmap, and not a shape. Therefore, if you try to draw something using the brush in Flash, it is going to go wonky on you. Additionlly, this should work with animated movieclips or video. I haven’t tested that functionality, but Ben built it into his original class so it should be good to go.

Reflection.as

This is the base class and will work on it’s own, but will not contain the horizon functionality.

/*
VERSION: 1.00
DATE: 12/17/2008
ACTIONSCRIPT VERSION: 3.0
UPDATES &amp;amp;amp;amp;amp;amp; MORE DETAILED DOCUMENTATION AT: http://www.hexluv.com
DESCRIPTION:
		A class that uses the BitmapData class to create a reflection of an library object.
		Credit goes to Ben Pritchard of pixelfumes.com for the majority of the work.

ARGUEMENTS:
	1) mc: - the movieclip you are intending to reflect
	2) alpha: - how transparent you would like the reflection (use 50 not .5)
	3) ratio: - the gradient mask ratio. e.g how much of the reflection is revealed (use whole integers)
	4) distance: - the distance from the bottom of the movieclip (measured in pixels)
	5) updateTime: - how often the reflection should be updated if its video or animated (in ms)
	6) reflectionDropoff: - the "quickness" of the gradient (use decimals)

EXAMPLE USAGE
	import com.matthaliski.effects.Reflection;
	var r:Reflection = new Reflection({mc:_myMC, alpha:50, ratio:50, distance:0, updateTime:0, reflectionDropoff:1});
*/
package matthaliski.effects {

	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.geom.Matrix;
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.utils.setInterval;
	import flash.utils.clearInterval;

	public class Reflection extends MovieClip {

		//reference to the movie clip we are reflecting
		public var mc:MovieClip;
		//the BitmapData object that will hold a visual copy of the mc
		private var mcBMP:BitmapData;
		//the BitmapData object that will hold the reflected image
		private var reflectionBMP:Bitmap;
		//the clip that will act as out gradient mask
		private var gradientMask_mc:MovieClip;
		//how often the reflection should update (if it is video or animated)
		private var updateInt:Number;
		//the size the reflection is allowed to reflect within
		private var bounds:Object;
		//the distance the reflection is vertically from the mc
		private var distance:Number = 0;
		//the reflection
		public var reflectionBMPRef:DisplayObject;
		//Container MovieClip
		public var container:MovieClip;

		public function Reflection(args:Object){
			/*the args object passes in the following variables
			/we set the values of our internal vars to math the args*/
			//the clip being reflected
			mc = args.mc;
			//the alpha level of the reflection clip
			var alpha:Number = args.alpha/100;
			//the ratio opaque color used in the gradient mask
			var ratio:Number = args.ratio;
			//update time interval
			var updateTime:Number = args.updateTime;
			//the distance at which the reflection visually drops off at
			var reflectionDropoff:Number = args.reflectionDropoff;
			//the distance the reflection starts from the bottom of the mc
			var distance:Number = args.distance;

			//Instantiate
			container = new MovieClip();
			mc.parent.addChild(container);

			//Place the container Sprite
			container.x = mc.x;
			container.y = mc.y;

			//Move the original MC inside the container
			mc.x = mc.y = 0;
			container.addChild(mc);

			//store width and height of the clip
			var mcHeight = mc.height;
			var mcWidth = mc.width;

			//store the bounds of the reflection
			bounds = new Object();
			bounds.width = mcWidth;
			bounds.height = mcHeight;

			//create the BitmapData that will hold a snapshot of the movie clip
			mcBMP = new BitmapData(bounds.width, bounds.height, true, 0xFFFFFF);
			mcBMP.draw(mc);

			//create the BitmapData the will hold the reflection
			reflectionBMP = new Bitmap(mcBMP);
			//flip the reflection upside down
			reflectionBMP.scaleY = -1;
			//move the reflection to the bottom of the movie clip
			reflectionBMP.y = (bounds.height*2) + distance;
			trace("The original MC y value is: " + mc.y);
			trace("The bounds height is: " + bounds.height);
			trace("The reflection's y value is: " + reflectionBMP.y);

			//add the reflection to the movie clip's Display Stack
			reflectionBMPRef = container.addChild(reflectionBMP);
			reflectionBMPRef.name = "reflectionBMP";

			//add a blank movie clip to hold our gradient mask
			var gradientMaskRef:DisplayObject = container.addChild(new MovieClip());
			gradientMaskRef.name = "gradientMask_mc";

			//get a reference to the movie clip - cast the DisplayObject that is returned as a MovieClip
			gradientMask_mc = container.getChildByName("gradientMask_mc") as MovieClip;

			//set the values for the gradient fill
			var fillType:String = GradientType.LINEAR;
		 	var colors:Array = [0xFFFFFF, 0xFFFFFF];
		 	var alphas:Array = [alpha, 0];
		  	var ratios:Array = [0, ratio];
			var spreadMethod:String = SpreadMethod.PAD;

			//create the Matrix and create the gradient box
		  	var matr:Matrix = new Matrix();

			//set the height of the Matrix used for the gradient mask
			var matrixHeight:Number;
			if (reflectionDropoff<=0) {
				matrixHeight = bounds.height;
			} else {
				matrixHeight = bounds.height/reflectionDropoff;
			}

			matr.createGradientBox(bounds.width, matrixHeight, (90/180)*Math.PI, 0, 0);

			//create the gradient fill
			gradientMask_mc.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
		    gradientMask_mc.graphics.drawRect(0,0,bounds.width,bounds.height);

			//position the mask over the reflection clip
			gradientMask_mc.y = container.getChildByName("reflectionBMP").y - container.getChildByName("reflectionBMP").height;

			//cache clip as a bitmap so that the gradient mask will function
			gradientMask_mc.cacheAsBitmap = true;
			container.getChildByName("reflectionBMP").cacheAsBitmap = true;

			//set the mask for the reflection as the gradient mask
			container.getChildByName("reflectionBMP").mask = gradientMask_mc;

			//if we are updating the reflection for a video or animation do so here
			if(updateTime > -1){
				updateInt = setInterval(update, updateTime, mc);
			}

		}

		public function setBounds(w:Number,h:Number):void{
			//allows the user to set the area that the reflection is allowed
			//this is useful for clips that move within themselves
			bounds.width = w;
			bounds.height = h;
			gradientMask_mc.width = bounds.width;
			redrawBMP(mc);
		}
		public function redrawBMP(mc:MovieClip):void {
			// redraws the bitmap reflection - Mim Gamiet [2006]
			mcBMP.dispose();
			mcBMP = new BitmapData(bounds.width, bounds.height, true, 0xFFFFFF);
			mcBMP.draw(mc);
		}
		private function update(mc):void {
			//updates the reflection to visually match the movie clip
			mcBMP = new BitmapData(bounds.width, bounds.height, true, 0xFFFFFF);
			mcBMP.draw(mc);
			reflectionBMP.bitmapData = mcBMP;
		}
		public function destroy():void{
			//provides a method to remove the reflection
			container.removeChild(container.getChildByName("reflectionBMP"));
			reflectionBMP = null;
			mcBMP.dispose();
			clearInterval(updateInt);
			container.removeChild(container.getChildByName("gradientMask_mc"));

		}

	}

}

ReflectionHorizon.as

This class extends Reflection.as and adds the horizon effect. It makes it seem as if the bitmap is disappearing into the horizon line.

/*
VERSION: 1.01
DATE: 1/5/2009
ACTIONSCRIPT VERSION: 3.0
UPDATES & MORE DETAILED DOCUMENTATION AT: http://www.hexluv.com
DESCRIPTION:
		A subclass of the Reflection class that adds the simulation of a horizon

ARGUEMENTS:
	1) mc: - the movieclip you are intending to reflect
	2) alpha: - how transparent you would like the reflection (use 50 not .5)
	3) ratio: - the gradient mask ratio. e.g how much of the reflection is revealed (use whole integers)
	4) distance: - the distance from the bottom of the movieclip (measured in pixels)
	5) updateTime: - how often the reflection should be updated if its video or animated (in ms)
	6) reflectionDropoff: - the "quickness" of the gradient (use decimals)

EXAMPLE USAGE
	import com.matthaliski.effects.Reflection;
	var r:ReflectionHorizon = new ReflectionHorizon({mc:_myMC, alpha:50, ratio:50, distance:0, updateTime:0, reflectionDropoff:1});

UPDATE 1.01
	1) Changed the mask to fill the entire stage rather than having the mask follow the movieclip around. Increases performance
	2) Set a fixed height for the original movie clip. Allows for dynamically expanded "hit states" should you want to use this as a button
*/

package matthaliski.effects {

	//Extends the basic reflector class
	import matthaliski.effects.Reflection;
	//For Events
	import flash.events.*;
	//For Timer (used to update display)
	import flash.utils.Timer;
	//For drawing capabilities (used for rectangular mask)
	import flash.display.*;
	import flash.geom.*;

	public class ReflectionHorizon extends Reflection {

		//the horizon of the reflection
		private var _horizon:Number;
		//distance from the horizon
		private var _horizonD:Number;
		//height of of the original movie clip
		private var _mcHeight:Number;
		//height of movie clip (including reflection)
		private var _mcFullHeight:Number;
		//Rectangle used for mask
		public var _mcMask:Shape = new Shape();
		//Rectangle used for reflection mask
		private var _reflectionMask:Shape = new Shape();

		public function ReflectionHorizon(args:Object) {

			//Runs the constructor method of the parent class
			super(args);

			//Determine horizon
			_horizon = mc.y + mc.height;

			//Set the original height
			_mcHeight = mc.height;

			//Set the initial height of the movieClip
			_mcFullHeight = mc.height;

			//Determine distance from the horizon
			_horizonD = _horizon - (mc.y + mc.height);

			//Sets timer to update reflection location based off of
			//parent mc movement
			var timer:Timer = new Timer (10, 0);

			//Add event listener to timer
			timer.addEventListener(TimerEvent.TIMER, updateHeight);

			//Starts the timer
			timer.start();

			//Perform calculations to get mask dimensions
			var _maskHeight:Number = mc.parent.stage.stageHeight - (mc.parent.parent.y + mc.height);
			_maskHeight = mc.parent.stage.stageHeight - _maskHeight;

			//Draws a rectangle to mask the actual mc
			_mcMask.graphics.lineStyle();
			_mcMask.graphics.beginFill(0xFFFFFF, .1);
			_mcMask.graphics.drawRect(0, 0, mc.parent.stage.stageWidth, _maskHeight);
			_mcMask.graphics.endFill();

			//Adds to the display list
			mc.stage.addChild(_mcMask);

			args.mc.mask = _mcMask;

		}

		//function that performs logic for reflection location
		private function updateHeight(evt:Event):void {

			//Keep the distance from the horizon updated
			_horizonD = _horizon - (mc.y + _mcHeight);

			//Adust the y value of the reflection
			reflectionBMPRef.y = (_mcHeight*2) + _horizonD;

			//Ensures the reflection follows the original mc
			reflectionBMPRef.x = mc.x;

			//Ensures the gradient mask follows the reflection along the x axis
			container.getChildByName("gradientMask_mc").x = mc.x;

		}	

	}

}

Conclusion

I’ll probably end up extending this just a bit further. I think I am going to need a fixed horizon as opposed to a dynamically generated one based on the height of the original movieclip being reflected. Hope everyone likes it.

Posted in Flash/ActionScript, Flash/ActionScript, Freebs | Tagged , , , | 3 Comments

Espresso Public Beta

Well, if you’re a developer worth your salt you’ve at least tried out CSSEdit at one point or another. Those same folks that brought you wonderful application are now pushing out Espresso. No, they didn’t lose their jobs as developers and start serving coffee as a fallback. They’ve just come out with a new app that in a small way mirrors some of the features of the new Dreamweaver. The public beta is available for download right now.

Espresso is not a bunch of apps forcibly smashed together. Instead, we looked at the needs of modern web developers and streamlined their workflow into one focused app. Extremely powerful editing, sleek projects, live preview (we make CSSEdit!), real publishing and extensive synchronization tools. All this, and an amazing extensible core? It’s not too good to be true. It’s now in public beta.

It is very much in Beta. I didn’t see a lot of the features in their screen shots. And it did actually crash my computer once. But, I trust they will have all the bugs worked out in due time. I’d definitely go check it out and throw a bookmark on it if I were you.

An all in one web developer app

An all in one web developer app

Posted in Industry News, Web Development | Tagged , , , , , | 2 Comments

ActionScript (AS3) Inheritance

Inheritance is a funny thing in ActionScript and Flash. But it does closely resemble the animal kingdom in which we live. Inheritance is also one of the cornerstones of object oriented programming. So get used to it! It essentially means that you can create new classes, often called subclasses, that inherit the methods and properties of a super or parent class. As I said, this is very similar to the animal kingdom. For instance, a monkey is going to inherit many of the characteristics of his parents, but he will also have the opportunity to develop on his own. Thus, giving him his own personality and physical features. If he decided to sit around all day and eat candy, he would probably end up being a fat monkey even though his parents are in phenomenal shape.

It’s a simple concept that can lead to diverse and complex programming. But, have no fear. It’s damn easy. As long as you know what you’re doing!

Let’s start with an example parent class. The following is a parent class for the adult monkeys mentioned earlier.

package {

   public class ParentMonkeys extends Sprite {

      public function ParentMonkeys() {

         trace("We are the parent monkeys!");

      }

   }

}

The above class only action is to trace out the string “We are the parent monkeys!.” Great. Now we want to create a subclass that extends the actions of the parent class. To do this, we start with a new ActionScript file and write the following:

package {

   public class CandyEatingMonkey extends ParentMonkeys {

      public function CandyEatingMonkey() {

         trace(" And I am their candy eating child:)");

      }

   }

}

The key to this is line 3 from above. Specifically, CandyEatingMonkey extends ParentMonkeys. By extending the class we gain access to all the methods and properties in the class. For example, maybe the parent class has a method that makes the parent monkeys stand on their heads. After we’ve extended the parent class we have full control to run that method. Thus, CandyEatingMonkey could make his parents stand on their heads all day long. Unfortunately, this particular functionality doesn’t carry over to the animal kingdom. Otherwise my childhood would have been a touch more humorous.

That is really the basics of inheritance. I could go on and on with examples, but I think my monkeys have done a pretty good job of explaining what inheritance is and how it works. Some other things to consider.

1203 Errors – No default constructor found in base class

When you’re first starting out creating subclasses you may run into some 1203 errors. These usually occur when the constructor function of the parent class is expecting an argument. In English that means it was expecting to be given some data in order to perform a subsequent action. If no data is given, you get the error.

To fix it, just pass in the arguments to the subclass and then evoke the super() method. Put whatever arguments you passed in inside the super() method like so:

package {

	public class CandyEatingMonkey extends ParentMonkeys {

		public function CandyEatingMonkey(arguments:Type) {

			super(arguments);
			trace(" And I am their candy eating child:)");

		}

	}

}

I’ll post some more details a little later.

I have to go pack the Jeep to go skiing. Say hi to the monkeys for me!

Posted in Flash/ActionScript, Web Development | Tagged , , , | Leave a comment