Posted by: coldfusionflex | March 16, 2008

WTF are they *thinking*?

I’m working on an AIR app today and I’m trying to compare my system time with the current time in New York (I’m in California). So the first thing I want to do is to see if the date flipped over already in New York. I compare my local system date with the date coming back from the remote server. Seems pretty simple.

According to Adobe:

http://livedocs.adobe.com/labs/flex3/langref/Date.html

Date() Constructor

  • If you pass no arguments, the Date object is assigned the current date and time.

So I create an Date object:

var todaysDate :D ate = new Date();
trace(“todaysDate: ” + todaysDate.month + “/” + todaysDate.date + “/” + todaysDate.fullYear);

and the trace comes out as “todaysDate: 2/15/2008″

I’m scratching my head. I’m pretty sure it’s March, so I reboot and check the system date. Sure enough, it’s March. OK…So I start looking around:

http://bugs.adobe.com/jira/browse/SDK-14658

“Not a bug. Dates in ActionScript are zero based. For more information, see: http://livedocs.adobe.com/labs/flex3/langref/mx/controls/DateChooser.html#displayedMonth

Now this might not be a *bug*, but it’s freakinSTOOPID. The days aren’t zero based. Why should the months be? I don’t where these guys grew up, but since when has January been month zero? Apparently on Planet Adobe January 1, 2008 is annotated 1/0/2008. Makes perfect sense to me.

I guess I’ve never run into this before because every time I’ve used the Date() it’s been relative…relatively WRONG.

Come on, guys…why should I have to write extra code to try to figger out the MONTH on my local computer?

Posted by: coldfusionflex | March 16, 2008

NativeApplication.nativeapplication.startAtLogin

So I’m trying to set some user preferences on an AIR app and one includes if the app should start on login. I run the app in FlexBuilder and I get a RTE when the function gets called:

Error #2014: Feature is not available at this time

Turns out this is an AIR bug:

http://bugs.adobe.com/jira/browse/SDK-14282

The suggestion is that one should:

“evaluate if you are in the IDE before setting this property”

Any clues about how one might actually *do* this in ActionScript? I’ve searched to no avail.

Posted by: coldfusionflex | March 16, 2008

DragBitmap.as

Christophe Coenraets (http://coenraets.org/) put together a pretty kewl class to drag a bitmap from an AIR app to the desktop. Unfortunately the classes changed between Beta3 and the final release and the version he has on his site no longer works. This version works with the current release.

It’s called like this:

<utilities:DragBitmap displayObject=”{theObject}/>

The package itself:

package {

	import com.adobe.images.JPGEncoder;

	import flash.desktop.Clipboard;
	import flash.desktop.ClipboardFormats;
	import flash.desktop.NativeDragManager;
	import flash.desktop.NativeDragOptions;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;

	import mx.formatters.DateFormatter;

	public class DragBitmap
	{
		private var _displayObject:DisplayObject;
		private var dateFormatter:DateFormatter;

		public var dragIcon:BitmapData;

		public function DragBitmap()
		{
			var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
				function ():void
				{
					dragIcon = Bitmap(loader.content).bitmapData;
				}
			);
			loader.load(new URLRequest("assets/icons/icon_image.png"));
			dateFormatter = new DateFormatter();
			dateFormatter.formatString = "YYYY-MM-DD-HH-NN-SS";
		} 

		public function set displayObject(displayObject:DisplayObject):void
		{
			_displayObject = displayObject;
			_displayObject.addEventListener(MouseEvent.MOUSE_MOVE, startDragging);
		}

		private function startDragging(event:MouseEvent):void
		{
			if (!event.buttonDown)
			{
				return;
			}

			var options:NativeDragOptions = new NativeDragOptions();
			options.allowCopy = true;
			options.allowLink = true;
			options.allowMove = false;

			var data:Clipboard = new Clipboard();
			data.setData(ClipboardFormats.BITMAP_FORMAT, getBitmapData(), false);
			data.setData(ClipboardFormats.FILE_LIST_FORMAT,[createTempJPG()]);

			NativeDragManager.doDrag(_displayObject as InteractiveObject, data, dragIcon, null);
		}

		private function getBitmapData():BitmapData
		{
			var bd:BitmapData = new BitmapData(_displayObject.width, _displayObject.height);
			bd.draw(_displayObject);
			return bd;
		}

		private function createTempJPG():File
		{
			var file:File = File.createTempDirectory().resolvePath("data-"+dateFormatter.format(new Date())+".jpg");
			var fileStream:FileStream = new FileStream();
			fileStream.open(file, FileMode.WRITE);
			fileStream.writeBytes(encodeJPG());
			fileStream.close();
			return file;
		}

		private function encodeJPG():ByteArray
		{
			var jpgEncoder:JPGEncoder = new JPGEncoder();
			var bytes:ByteArray = jpgEncoder.encode(getBitmapData());
			return bytes;
		}

	}
}

Categories

Follow

Get every new post delivered to your Inbox.