Posts Tagged ‘AS3’

Stacktrace, anywhere, anytime.

Posted in Flash on May 20th, 2009 by hp. – Be the first to comment

A quick one here to output your current call-stack.
Useful when you need to know who the hell is nullifying that property.

        try { throw new Error("----STACKTRACE----") }
        catch (e:Error) { trace(e.getStackTrace()) }

Using namespaces for something useful

Posted in Flash on May 4th, 2009 by Simen – 1 Comment

If you’ve ever used namespaces in AS3 you’ve probably done something like trying to parse XML containing one or more namespaces which arguably is a pain most of the time. Namespaces however have some other uses that can be quite helpful.

For the examples I’ve defined two namespaces in an external class, while you can define namespaces in-line it isn’t very reusable.

class Environment {
	namespace development = "dev";
	namespace production = "prod";
}

Using the same configuration file for several different environments
(this also allows you to switch the environment at run-time)

var data:XML = 
	<config xmlns:dev="dev" xmlns:prod="prod">
		<dev:gateway>http://local-server/gateway</dev:gateway>
		<prod:gateway>http://www.client-server.com/gateway</prod:gateway>
	</config>;
 
// Directly referencing the namespace
var ns:Namespace = Environment.development;
trace(data.ns::gateway); // http://local-server/gateway
 
// Using a specificed namespace
use namespace Environment.production;
trace(data.gateway); // http://www.client-server.com/gateway

Make functions perform differently depending on environment

Environment.production function doSomething():void {
	trace("Production Parrot");
}
 
Environment.development function doSomething():void {
	trace("Development Dino");
}
 
// Using a namespace adds it to the list of namespaces to look up, it lasts for a code block
use namespace Environment.development;
 
doSomething();
 
// use namespace Environment.production; // This won't work since the reference to the function is ambiguous
 
// However this will since the namespace list is only valid for one code block.
function someFunction():void {
	use namespace Environment.production;
	test(); // Production Parrot
}
 
someFunction();

Joa and co. open source Hobnox

Posted in Flash on April 28th, 2009 by Alexander – Be the first to comment

Starting with the UIEvent framework, parts of the Hobnox editing tool are being open sourced. Hopefully we will see more of the juicy bits we’ve been teased with for so long.

Dive in

51 AS optimizations

Posted in Flash on April 23rd, 2009 by Alexander – Be the first to comment

Sean Moore has collected 51 coding optimizations for AS3 and Flex: read about them here

Force import of Class in compiled code.

Posted in Flash on April 16th, 2009 by hp. – Be the first to comment

As you know; import statements do not add classes to a compiled swf unless referenced elsewhere.

When you need code you don´t use into the swf/swc you may simply reference your class right after the import.

package {
  import flash.events.Event; //Not necessarily imported
  import views.ui.ReallyNeedThis; ReallyNeedThis; //Imported for sure, make note of the semicolon.
//...
}

AS3 Libary for Facebook Platform

Posted in Flash on April 16th, 2009 by Jesper – Be the first to comment

Adobe releases code libary for easy intergration with facebook platform.

http://www.adobe.com/devnet/facebook/

ToneMatrix by Andrè Michelle

Posted in Flash on April 15th, 2009 by Thomas N – Be the first to comment

Searching for some soundmanipulation, I came across this sweet tool.
lab.andre-michelle.com/tonematrix

I also added his blog to the bloglist, alot of interesting research there :)