"7actionscript" Posts

Tip of the Day – Flex Builder, Open Resource shortcut

So while thinking about the tip I wanted to write today… I thought about my development process, and trying to identify things that I do to speed up my development. That way I can share them with all of you.

One thing that has become second nature to me is the use of the Open Resource shortcut in Eclipse (and therefore Flex Builder). This handy little shortcut is a life saver.

For all the pcs: ctrl + shift + R
For all the macs: ⌘ + shift + R

Open Resource Panel

This panel allows you the type in the resource you want to open, even if it is open already, and will bring it to focus. It’s amazing! Use it, love it, cherish it.

Tip of the Day – Use your logo as your widget’s pre-loader

This is one of those no-brainers, but you’d be surprised how many widgets out there don’t do this.

If you keep your widget size small, and offload your assets to later frames in your swf, you can easily get your brand noticed on a whole lot more social network profiles. This is because your typical social network profile has trillions of photos, slideshows, music, you name it crowding the page.

If your pre-loader has your logo, and your widget loads before almost everything else on the page, then by the transitive property of equality… users will see your logo. It’s as simple as that.

Tip of the Day – Mouse wheel scrolling on the mac

A friend of mine asked me yesterday if I would take a look at a Flex application that he was writing. I said, “of course!”, and pulled up his app in my browser. To my surprise, I couldn’t for the life of me figure out how to navigate through his application.

So I called him back as asked him. He told me that his app uses the mouse wheel quite a bit to navigate around, he thought it would be very intuitive. I guess not everyone knows that mouse wheel scroll events don’t register on the mac.

So today I’m letting everyone within the sound of my blog know that…

Mouse wheel scrolling does not work on Macs… natively!

Luckily for us, Ali Rantakari has created a solution for this very problem. You can read up about the solution in this post.

Tip of the Day – Proxies… Make ‘em dynamic

A couple of days ago, I was working on my DateTime proxy class.

DateTime.as (Trimmed version)

package net.natebeck.core
{
	import com.flexoop.utilities.dateutils.DaylightSavingTimeUS;
 
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;
 
	public class DateTime extends Proxy
	{
		// Instance Variables
		protected var _date:Date;
		protected var _timezone:Timezone;
 
		public function DateTime(... args)
		{
			super();
 
                       _date = new Date(args[0]);
		       if(args[0] is String)
		            setTimezone(parseTimezone(args[0]));
		}
 
		public function setTimezone(value:Timezone):void
		{
			trace("Setting Timezone: "+value);
			_timezone = value;
		}
 
		public function getTimezone():Timezone
		{
			trace("Getting Timezone: "+_timezone);
			return _timezone;
		}
 
		public function getTimezoneOffset():Number
		{
			return _timezone.offset;
		} 
 
		override flash_proxy function callProperty(methodName:*, ... args):*
		{
			var res:*;
	        switch (methodName.toString()) 
	        {
	            case 'toString':
	            	res = "foobar";
	            	break;  
	            default:
	                res = _date[methodName].apply(_date, args);
	                break;
	        }
	        return res;
		}
 
		override flash_proxy function getProperty(name:*):* {
			trace("getting property: "+name);
	        return _date[name];
	    }
 
	    override flash_proxy function setProperty(name:*, value:*):void {
	        _date[name] = value;
	    }
 
	}
}

I wrote a simple test application to test my DateTime Proxy class while I’m developing.

TestDateTime.as

package
{
	import flash.display.Sprite;
 
	import net.natebeck.core.DateTime;
	import net.natebeck.core.Timezone;
 
	public class TestDateTime extends Sprite
	{
		public function TestDateTime()
		{
			var create:Object = "Jun 17 12:00:00 GMT-0500 2009";
 
			var oldDate:Date = new Date(create);
			var strDate:DateTime = new DateTime(create);
 
			trace("old: "+oldDate);
			trace("new: "+strDate);
 
			strDate.getTimezone();
			strDate.setTimezone(Timezone.PST);
			strDate.getTimezone();
 
			trace(strDate.toString());
 
 
		}
 
	}
}

When trying to compile using Flex Builder I ran into this error:

ERROR 1061: Call to a possibly undefined method toString through a reference with static type net.natebeck.core:DateTime.

I thought to myself, “Well that’s lame… the whole reason I’m using the Proxy class is so I don’t have to re-write every method within my class”.

As usual, the issue wasn’t with the compiler, it was me being dumb. Computers… they’re always right.

The answer was simple, and makes complete sense after someone mentioned it.

When creating your own Proxy class, make them dynamic!

public dynamic class DateTime extends Proxy

If you’re confused about when or why to use the flash.utils.Proxy class, I gave a presentation yesterday at the Seattle Flex User Group about the Proxy class. My presentation materials are posted here.

I’d also like to thank Dale and Josh McDonald for quickly responding to my question on flexcoders.