Matt Kenefick
Contact Me Experiments Blog Portfolio

Archive for October, 2008

AS3.0 Type Casting, what is the deal?

Friday, October 31st, 2008

I recently had someone ask me the difference between using:

MovieClip( object );
// and
object as MovieClip

I ran some tests to show the example of what actually happens and here you go:

var o:Object = "test"; 
 
trace( 'MovieClip: ' + o as MovieClip );
// displays: null 
 
trace( 'Array: ' + o as Array );
// displays: null 
 
trace( 'Object: ' +o as Object );
// displays: Object: test 
 
trace( 'String: ' +o as String );
// displays: String: test 
 
trace( 'Boolean: ' + Boolean(o) );
// displays: Boolean: true
 
trace ( 'MovieClip: ' +MovieClip ( o ) );
// generates a TypeError

Using the MovieClip( x ) or Boolean( x ) method tries to do a Type Conversion. The Boolean succeeds because it finds that there IS a value available and converts to true. If the value were NULL, it would read false. MovieClip fails because the type just does not match.

When you cast using “as”, it seems to attempt a Try/Catch basically. It will return a null if unavailable, but will not crash your application.

Because a Sprite is below a MovieClip in the inheritance chain, it cannot cast it’s way up.
Worthy of noting: MovieClips are dynamic classes. Sprites are not. Only dynamic classes can receive custom (dynamic) variables. This means you can assign whatever variable you want to a MovieClip, but do not try that with a Sprite.

var mc:MovieClip 	= 	new MovieClip();
mc.customVar 		= 'matt';
trace(mc.customVar);
// traces: matt
 
var newmc:MovieClip 	= 	MovieClip(mc);
trace(newmc.customVar);
// traces: matt
 
var newsp:Sprite 	= 	Sprite(mc);
trace(newsp.customVar);
// undefined property error

If you try to set a Sprite, then cast it as a MovieClip, you will get a Type Coercion error.

var sp:Sprite 		= new Sprite();
var mc:MovieClip 	= MovieClip(sp);
// error
trace(mc);

What does it all mean?

Type Casting is a one-way trip down the inheritance chain. Your basic MovieClip inherits like this:

MovieClip -> Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher -> Object

This is why a MovieClip can cast down to a Sprite, but a Sprite cannot cast up. You can take something away (cast down)… but you cannot create something from nothing (cast up).

Looking for judges…

Friday, October 31st, 2008

For my new PORT project. ( http://mattkenefick.com/blog/2008/10/port-my-new-project/ )

Needs to be:

  •    Well versed in AS 2.0 and AS 3.0
  •    Understands good design patterns / practices
  •    Good coding conventions
  •    Deep understanding of the words “Why” and “Why Not”
  •    Interested in helping the Flash community pro-bono
  •    Able to work with me in grading submitted projects
  •    Has creative ideas for faux-projects

If this is something you might be interested in… leave a comment or shoot me an email ( keneficksays@gmail.com ). I am hoping to launch this relatively soon and could use a hand in getting things moving.

If not, you are still free to participate!

Sound Visualization Bug in Flash

Thursday, October 30th, 2008

This is something interesting I stumbled upon. I was listening to a station on Pandora.com then I went to my experimentation site ( http://www.jureuxoris.com ). I tried looking at my Sound Visualization examples. The music would play but the sound visualization would not show up. I closed the Pandora tab and refreshed my Sound Visualization and then it worked.

Next, I went to Purevolume.com and used one of their players to see if it was other Flash players in general or just Pandora.com. Same thing happened.

It seems as though if there is another Flash player playing sound in a different tab, your sound visualization will not work. The sound will play but it will not be able to read it.

Interesting…

Working on a fix…

Detecting subtleties in Photoshop documents

Thursday, October 30th, 2008

A lot of designers, especially minimalistic designers, like to use subtleties in their designs. What I mean is using icons or color changes that really blend. Your eye can understand that they are there, but it is hard to really see where they start and end. Designers often use very very light lines to divide things which may make it hard for a programmer to notice. If you are ever working with a real subtle layout, check out this example that may help you target where everything is.

Normal Layout Where are the details?

Layout with Color Burn Ahh.. there it all is..

To achieve this, simply create a layer on top of everything.. Fill it with green.. set the blend mode to “Color Burn”.

You’ll see all those subtle lines, strokes, and gradients show up vividly.

Point around a perimeter

Thursday, October 30th, 2008

This will find a point outside of a specified object. Good for games perhaps if you need random placement outside of something like a building or whatnot.

Actionscript 3.0

// example does not take into account width of object
// being used
var stageHeight = 400;
var stageWidth 	= 550;
 
// width priority
var w,nw,h,nh,wp = 0;
 
function setRandomPoint(e:TimerEvent = null){
	wp = Math.round(Math.random());
	if(!wp){
		// gives priority to height
		w = Math.random()*(stageWidth-mc.width);
		nw = (w>mc.x)?w+mc.width:w
		nh = Math.random()*(stageHeight);
	}else{
		// gives priority to width
		nw = Math.random()*(stageWidth);
		h = Math.random()*(stageHeight-mc.height);
		nh = (h>mc.y)?h+mc.height:h
	}
 
	point_mc.x = nw
	point_mc.y = nh
 
}
 
var timer:Timer=new Timer(200);
timer.addEventListener(TimerEvent.TIMER, setRandomPoint);
timer.start();

Classy drop shadows for objects

Wednesday, October 29th, 2008

Want to create these types of shadows?

The following code will analyze the width of your selected object, even if it is centered within the clip, and create a shadow for it. You can specify the offset from the object, the fade amount, and the height of the shadow (which would specify angle of view).

Actionscript 3.0

function createShadow( item:MovieClip, offset = 10, fade:Number = 1, shadowHeight:int = 20 ){
	var itemShadow:Sprite 	= new Sprite();
	var gfx:Graphics		= itemShadow.graphics;
	var matrix:Matrix 		= new Matrix();
	var realDimensions 	= item.getBounds(item.parent);
 
	matrix.createGradientBox( item.width, item.height );
	gfx.beginGradientFill("radial", [0x000000, 0x000000], [fade,0],[0,255],matrix);
	gfx.drawRect(0,0,item.width,item.height);
	gfx.endFill();
 
	itemShadow.y 		= 	realDimensions.y + item.height + offset;
	itemShadow.x 		= 	realDimensions.x;
	itemShadow.height 		=	shadowHeight;
	itemShadow.blendMode	=	"multiply"
 
	addChild( itemShadow );
}
 
createShadow( item1_mc, 50, .5, 10 );
createShadow( item2_mc, 20, .7, 15 );

Actionscript 2.0

import flash.geom.Matrix;
 
function createShadow( item:MovieClip, offset, fade:Number, shadowHeight:Number ){
	fade 	= fade ? fade : 50;
	offset 	= offset ? offset : 50;
	shadowHeight = shadowHeight ? shadowHeight : 10;
 
    var itemShadow:MovieClip   	= item._parent.createEmptyMovieClip('itemShadow', item._parent.getNextHighestDepth());
    var matrix:Matrix    		= new Matrix();
    var realDimensions   		= item.getBounds(item._parent);
 
    matrix.createGradientBox( item._width, item._height );
    itemShadow.beginGradientFill("radial", [0x000000, 0x000000], [fade,0],[0,255],matrix);
	itemShadow.moveTo(0,0);
	itemShadow.lineTo(item._width,0);
	itemShadow.lineTo(item._width,item._height);
	itemShadow.lineTo(0,item._height);
    itemShadow.endFill();
 
    itemShadow._y          =  realDimensions.yMin + item._height + offset;
    itemShadow._x          =  realDimensions.xMin;
    itemShadow._height     = shadowHeight;
    itemShadow.blendMode    =   "multiply"
}
 
createShadow( item1_mc, 50, 50, 10 );

We are all on sale. And that is okay.

Sunday, October 26th, 2008

Not physically of course. Except for hookers, I am sure they have their sales.

What I mean is this… Macy’s has a 2-day weekend only sale about every two weeks. Why? It attracts customers because they think that it is the only time they will get a deal on something. If there was no sale, people would go if they wanted to buy something. When there is a sale, people feel the need to buy something for no reason just because it is cheaper.

The limitations, the chase, is always the most interesting part of life. Guys seem to put a lot of effort into getting a woman when he cannot have her. After some time of having her, interests tend to change. This is not always the case, but you cannot deny seeing this. Games are always more fun to play when you scarcely have the opportunity to. As soon as you own it, you hardly ever play it.

Why do we die? Well, there are a hundred reasons. I like to think that one of them is because of how boring it would be to live for too long. If you know your time alive is limited, you put more effort into doing what you want to do. “I have to be married by 35.” Why? Because you are running out of time.

So technically… We are all on sale. For the limited time of 80-90 years. Get what you want out of us before our offer expires. But do not worry, our sale will be back again soon enough.

Future of human education…

Sunday, October 26th, 2008

Is a very scary thing. We are already experiencing it but when all this new technology becomes standard, and all the future technology becomes standard, we are going to be in for a very serious rude awakening. Technologies right now are advancing. People are learning the simplified techniques for accessing it. If you are a programmer, and you write in PHP or Actionscript or Perl or any language of your choice.. you are part of it. The language you write is translated to the core which then gets processed by the computer. If something goes wrong in the core, most of you have absolutely no idea what to do. You can speak the language, but you do not REALLY know what it means. You understand the actions that it translates to, but not HOW.

Example of what I am talking about: I currently work in a building with very old elevators. One of them is constantly broken while the other is constantly being *fixed*. Strangely enough, the people that fix our elevators never run out of work in our building. So much for the fixing part. When I was in San Francisco, I had the exact same issue. If you go up to the roof and actually look in this elevator room… each elevator is controlled by a very large, very old switchboard. They look a little something like this:

 

When you press a button in your elevator, this switchboard lights up like the Fourth of July skyline. If you have two elevators, each of them has this switchboard and a middle switchboard to control the two. There are wires all over, pulleys, bike chains, and that good stuff.

The point is that the elevator in California never got fixed while I was there. The reason was, “There are only a handful of people in the country that know how to fix these and they are all busy.” So the technology is still around but no one knows how to actually control it. Attack of the malevolent elevators, right?

Elevators are not so scary, but nano-ants are. We are at the point where they are introducing nanotechnology for medical purposes. It is the biggest no-no according to every science fiction writer in history. With enough time, people are going to start forgetting the basics and we will ultimately destroy ourselves… because of ourselves. It will not be from nukes, it will not be from toxins, it will be from our own forgetfulness and greed in knowledge. Humans are smart, we are evolving, some of us learn well, and that is just great! The problem is that we sacrifice the “smaller details” for the “bigger picture”. It is only a matter of time before the smaller details catch up and kick us in the ass.

We are pushing the limits too far to a point where we cannot keep up. We are leaving a breadcrumb trail, but soon enough we are going to run out of bread. When that happens, we are going to us the bread we already laid down and eventually lose the path back home. The only way to fix this problem is to find a new way of learning. School is not cutting it anymore. We do not learn nearly fast enough to keep up with the things we need to know.

If we do not come up with a solution soon enough, something will backfire in our future and there will be no one that knows how to fix it.

Sadly enough, I think this was the basis for the movie Demolition Man. Great movie, terrible acting, better idea. If you have not seen it, it has to do with a person from the past coming alive and causing chaos that the future generation does not know how to handle. Check it out. You will probably regret it, but do it anyway.

PORT: My New Project

Thursday, October 23rd, 2008

Project Objective Requirements Training

Project Objective Requirements Training

PORT: Project Objective Requirements Training. This is the start of a new project. It is basically going to be a website that will offer tests for those interested but lack ideas. It is hard to create something from nothing, especially when you have no resources to work with. Think of it like a voluntary schooling where grades do not matter.
The biggest problems with school are:

  • Money
  • Grades
  • Parents
  • Other students
  • Bad teachers
  • Curriculum

When you take out a loan for school, most people do not feel like they are really paying for it. If they took the $20,000 out of your savings, you would feel it, but not with a loan. It leads to caring a little less about it.

Sometimes you feel like you need to have good grades or that your parents need to see an A in order to continue paying your tuition. It leads to stress that is not necessary.

Other students really drag the class down. When you waste an hour long class sitting there doing nothing because Joe Plumber Partys-All-The-Time does not know what he is doing… it really wastes YOUR time. The entire class, the entire curriculum, the entire everything is held up. Which leads to curriculum. It has to be generalized enough for the students that everyone can participate. If you are far ahead of your class, which I am sure you are, then you will just being annoyed the entire semester and not reach your potential.

Bad teachers will ruin your experience just as much as the rest of this. It is easy to be turned-off from a class you really like because of a bad teacher. In this world, Google and the internet are our teachers. Everyone is capable of learning on their own. If people really want to know, they will learn it. Teachers will tell you what you need to know to pass. It is more important to know why something works instead of just knowing the code that makes it work.

This site is intended to give people the experience free of charge and without the annoyances. The goal is to offer projects with the necessary information to get someone started. When a developer wants to practice building a site, or make something cool, it is hard when you are given a blank slate.

- What do you make?
- What can you use for a logo?
- What is the identity and the theme?

That is a lot of work to accomplish before you can even start developing. The identity and resources can be the backbone for development. A 3D Wall Photo Gallery could be a cool feature, but it is not always applicable.  This site will offer project sheets at different intervals (so the community can work together as a psuedo class ) that outline the specs. Some projects will be as simple as “Build a menu according to these specs.” Some projects will offer a faux company / identity / graphic resources and a task.

The community that chooses to participate will follow the time constraints per project, submit their work, and have it graded / posted on the website. All property remains that of the user. Projects that are handed in late are marked as so, and will not be showcased in the main section. They will be displayed, but not eligible for awards or such.

It is one thing to know how to build an MP3 Player. It is different thing to actually build one. The more often you do something, the easier it is to repeat in the future + the more bugs / improvements you find. Theory is great. Practice is better.

More details to come. Please leave comments / suggestions / thoughts on this.

Devunity: Collaboration

Wednesday, October 22nd, 2008

Not going to write a lot here… Just stumbled upon this and thought it could be interesting. Have a look:

 

http://www.devunity.com/