Flash Cafe

Are you a dick?

April 10th, 2009 nebutch

I came across the following image on Fark.com, and something about it tickled my geek bone.

PI

From FlashDevelop to xCode : Duplicate Line

April 6th, 2009 nebutch

So over the past month or so, I’ve decided to delve into the wonderful world of Objective-C and Cocoa. I’ve been using xCode as my primary IDE, and so far I love it. However, one nagging issue about xCode is that there is no “Duplicate Line” or “Delete Line” hotkey as there is in FlashDevelop, which I’ve been using for years for most of my AS development. While I *could* try to get used to the old “Option” + drag method or copy/paste, I found myself spoiled by the quick hotkey action that FD offers (which by default is Ctrl+D for duplicating and Ctrl+Shift+D for deleting. There’s also a handy “transpose” hotkey, which I won’t go into).

So doing some research, I came across a couple of options. One option requires that you create a User Script in xCode and assign whatever hotkey to that. You can find more information HERE. I decided not to use that solution because there was no “Delete line” code source, and I frankly wasn’t in the mood to learn Ruby in order to customize my own script (yet).

The second option is to create a Dictionary file and customize your script very easily using the Mac OSX Key Binding documentation as a reference. Here’s what you do:

- Create a new .dict file in the following directory : home/Library/KeyBindings/PBKeyBinding.dict
Note : If the KeyBindings directory does not exist, you’ll need to create it.

- Add the following code:

{
"^$K" = (
"selectLine:",
"cut:"
);
 
"^$D" = (
"selectLine:",
"copy:",
"moveToEndOfLine:",
"insertNewline:",
"paste:",
"deleteBackward:"
);
}

- Save the file, restart xCode if it was already open.

So with the above code, placing the cursor within any line then hitting the key combo ‘Control + Shift + K’ will delete that entire line, and hitting ‘Control + Shift + D’ will duplicate it.

Thanks to TypeOneError for posting the initial info on this. One thing that I did change from the original code is that I added a “deleteBackward” command at the end of the Duplicate Line section. This will place the cursor back at the end of the line just created, rather than at the beginning of a new line (which is more like what FD’s behavior is). The obvious beauty of this is that you can recursively hit the hotkey combo and duplicate lines without having to place your cursor back up into the previous one. You can further customize or add other bindings by referencing the Mac OSX Key Bindings documentation.

I may delve into this a bit more and see about a ‘Transpose’ hotkey, which switches placement of the last two selected lines of code, but I’m in no hurry.

Merry Christmas!

December 24th, 2008 nebutch

To celebrate both the holiday and my new gig with Animax Entertainment, here’s a little Christmas diddy. Canadian style, eh. :)


Mr. President

November 5th, 2008 nebutch

Congratulations, Barack Obama!

small_obama_image.jpg

I’m definitely proud as an American that we as a Nation came together and voted for change. Now that we chose, let’s all make sure that we stand behind our new President and do our parts to steer the USA into better waters - Democrats and Republicans alike.

Flash CS4: Using FileReference.load() for bitmaps

November 2nd, 2008 nebutch

Lee Brimelow did a nice tutorial a while back showing us how to load text into a browser based .swf using Flash’s new FileReference.load() method. Here’s how to take it a step further and load in a local bitmap, cast it as a Bitmap object, and resize it proportionally. I don’t include any code on actually uploading the file to a server, as that is another topic altogether, but if I get some demand for it, I’ll try to put together an example of doing that with PHP…

Here’s the code:

package
{
	import fl.controls.Button;
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	import flash.text.TextField;
	import flash.text.TextFieldType;
 
	import flash.events.MouseEvent;
	import flash.events.Event;
 
	public class  BitmapLoader extends MovieClip
	{
		private static const _MAX_WIDTH		: Number = 790;
		private static const _MAX_HEIGHT	: Number = 560;
 
		private var _fileRef			: FileReference;
		private var _fileFilter			: FileFilter;
		private var _loader			: Loader;
		private var _bitmap			: Bitmap;
		private var _browseBtn			: Button;
		private var _staticTxt			: TextField;
		private var _browseTxt			: TextField;
 
		public function BitmapLoader ( )
		{
			_init ( ) ;
		}
 
		private function _init ( ) : void
		{
			_staticTxt = new TextField ( ) ;
			_staticTxt.type = TextFieldType.DYNAMIC;
			_staticTxt.x = 10;
			_staticTxt.y = 10;
			_staticTxt.height = 21;
			_staticTxt.text = "Select an image:";
			addChild ( _staticTxt ) ;
 
			_browseTxt = new TextField ( ) ;
			_browseTxt.type = TextFieldType.INPUT;
			_browseTxt.x = _staticTxt.x + _staticTxt.width + 4;
			_browseTxt.y = 10;
			_browseTxt.height = 21;
			_browseTxt.width = 200;
			_browseTxt.border = true;
			_browseTxt.background = true;
			addChild ( _browseTxt ) ;
 
			_browseBtn = new Button ( ) ;
			_browseBtn.label = "Browse";
			_browseBtn.name = "browse";
			_browseBtn.x = _browseTxt.x + _browseTxt.width + 4;
			_browseBtn.y = 10;
			_browseBtn.useHandCursor = true;
			_browseBtn.addEventListener ( MouseEvent.CLICK, _handleMouseEvent ) ;
			addChild ( _browseBtn ) ;
 
			_fileFilter = new FileFilter ( "Image", "*.jpg;*.gif;*.png;" ) ;		
 
		}
 
		private function _handleMouseEvent ( evt : MouseEvent ) : void
		{
			switch ( String ( evt.target.name ))
			{
				case "browse" :
					_fileRef = new FileReference ( ) ;
					_fileRef.browse ( [_fileFilter] ) ;
					_fileRef.addEventListener ( Event.SELECT, _onImageSelect ) ;
					trace ( "Browse" ) ;
				break;
			}
		}
 
		private function _onImageSelect ( evt : Event ) : void
		{
			_fileRef.load ( ) ;
			_fileRef.addEventListener ( Event.COMPLETE, _onDataLoaded ) ;
			_browseTxt.text = String ( evt.target.name ) ;
		}
 
		private function _onDataLoaded ( evt : Event ) : void
		{
			var tempFileRef : FileReference = FileReference ( evt.target ) ;
			_loader = new Loader ( ) ;
			_loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, _onImageLoaded ) ;
			_loader.loadBytes ( tempFileRef.data ) ;
		}
 
		private function _onImageLoaded ( evt : Event ) : void
		{
			_bitmap = Bitmap ( evt.target.content ) ;
			_bitmap.smoothing = true;
			_bitmap.x = 5;
			_bitmap.y = _browseTxt.y + _browseTxt.height + 5;
			addChild ( _bitmap ) ;
 
			//Resize the image if needed
			if ( _bitmap.width > _MAX_WIDTH || _bitmap.height > _MAX_HEIGHT ) {
				_resizeBitmap ( _bitmap ) ;
			}
 
		}
 
		private function _resizeBitmap( target : Bitmap ) : void
		{
			if ( target.height > target.width ) {
				target.width = _MAX_WIDTH;
				target.scaleY = target.scaleX;
			} else if ( target.width >= target.height ) {
				target.height = _MAX_HEIGHT;
				target.scaleX = target.scaleY;
			}
 
		}
 
	}
 
}

And here’s a .zip including the FLA (must have CS4), SWF, AS, and JPG.

Enjoy ;)

Leave Sarah Palin ALONE!!!!

September 24th, 2008 nebutch

I normally don’t like to bring my political views outside the realm of friends and family, but the latest statement from Laura Bush has me in stitches. Here’s a quote from a recent press conference:

Mrs. Bush also said that she thinks Palin is being treated unfairly because she is a woman. That, the first lady says, is to be expected.

I have two issues with that statement…

First, we all know why Gov. Palin was picked for the #2 spot - get the Hillary voters. Fact is, she’s a woman. That’s a major factor in the GOP’s choice. It wasn’t ability to lead the nation, experience, foreign affairs, financial wizardry, or anything else that should be relevant to running the nation. Oh wait! She’s a hockey mom! That’s one thing at least… So to say that she’s getting any kind of treatment “because she’s a woman” is blatantly hypocritical.

Second,  it’s to be expected that she gets put through the ringer because 95% of our nation did not know who the hell this woman was before the veep announcement. I’m sure it’s safe to say that it would be expected for any candidate who the voters need more knowledge about so that we can make an informed decision at the polls. The fact that Sarah Palin happens to be a woman just puts ammo in the GOP’s shotguns, and gives them an easy way out.

So to prevent any further hurt feelings and possibilities of being sexist, I say to the media and common voter alike:

leavepalinalone.jpg

One more thing  - No matter who you think is the best candidate, get out and VOTE!! If you aren’t registered, go do it now…

Road Runner gets one more star from me..

September 23rd, 2008 nebutch

So I’m sitting here watching my Chargers play the Jets, and I see an ad for Time Warner’s Road Runner Turbo with PowerBoost (yeah, it’s a mouthful). I see that speeds of “up to 22mbps” are available for 9.95 more per month…

Now I’m thinking “wait, I already have Turbo. Do I have to pay the $10 a month more for an additional 8mbps over my current speed? Is it worth it if I have to?”. So off I go to the TWC website, looking for more info. I find that if you sign up for RR Turbo you get the PowerBoost feature for free.

Ok, fine. But what about existing customers of the plan? Nothing is mentioned about that. Off I go to www.speedtest.net to test my connection speed:

HOLY SHIAT! That’s.. um.. nearly 30mbps! Which is almost a full 16mbps over what I was getting before.. for the SAME PRICE!

So, TWC, that’s now 3 stars out of 5 for you! It would actually be 4 or 5, but as fast as the connection is, I still wonder from day to day if I’m going to even HAVE a connection. That would be fine and dandy if I just lose a day of downloading porn and youtube content, but I fully depend on my connection for my job.

And for those wondering “WTF is PowerBoost?”, it’s a feature of the service that “boosts” your internet speed when downloading large files. I’m not certain yet of what the minimum file size is to activate the open stream, but I’ve noticed over the last few days that files 1mb+ have been downloaded much faster than before.

I have to give TWC a kudos for this one. Now let’s just keep the connection active longer than 3 days straight, and I’ll think about that additional star :D

Web 2.0 and “Blogging”

September 21st, 2008 nebutch

I caught wind of this video exemplifying the OMG sooooo awesome wonders of the how’s, why’s and wtf’s of Web 2.0 and what it means to current civilization. Enjoy ;)


Flash CS4 to be official next Tuesday!

September 19th, 2008 nebutch

I don’t have many details, but I’ve come to find out that Adobe will be officially launching Flash CS4 on 9/23. I also know that this will be NOT be a release, but an unveiling. You can register to view a special webcast held by Adobe on the 23rd.

Update to Lee Brimelow’s ‘Dynamic Sound’ Tutorial

July 12th, 2008 nebutch

I don’t have time to go over the specifics of what is different, but here is the modified code to Lee Brimelow’s ‘Dynamic Sound’ tutorial that covers how to create sound dynamically in Flash 10. This code will work with the new Flash Player 10 Beta 2, but not with any prior version.

I can tell you that the main difference is in the Sound API, specifically with how the SampleDataEvent class is used. Also, we now invoke the ‘writeFloat’ method on the event object rather than an instance of the Sound class.

In addition, we will pass in a value of 8192 to the ‘for’ loop rather than 512. This results in superior sound quality, as indicated in the updated API documentation on the SampleDataEvent class:

Dispatched when the player requests new audio data.

Use this event when you want to manage dynamically generated audio. In this environment, the Sound object doesn’t actually contain sound data. Instead, it acts as a socket for sound data that is being streamed to it through the use of the function you assign to this event.

In your function, you use the ByteArray.writeFloat() method to write to a ByteArray object (event.data) that contains the sampled data you want to play.

When you call Sound.play(), the player starts calling your event handler, asking for chunks of data that contain sound samples. The player continues to send events as the sound plays back until you stop providing data, or until SoundChannel.stop() is called.

The latency of the event varies from platform to platform, and could change in future versions of Flash Player. Don’t depend on a specific latency, calculate it instead. To calculate the latency in ActionScript, use the formula: ((SampleDataEvent.position/44.1) - SoundChannelObject.position).

Provide between 2048 and 8192 samples in a SampleDataEvent object. For best performance, provide as many samples as possible. The fewer samples you provide, the more likely it is that clicks and pops will occur during playback. This behavior can differ on various platforms and can occur in various situations - for example, when resizing the browser. You might write code that works on one platform when you provide only 2048 samples, but that same code might not work as well when run on a different platform. If you require the lowest latency possible, consider making the amount of data user-selectable.

If you provide fewer than 2048 samples, Flash Player plays the remaining samples and then stops the sound as if the end of a sound file was reached, generating a SoundComplete event.

You can also use the Sound.extract() method to extract data from a Sound object, which you can then write to the dynamic stream for playback.

When you use this event with a Sound object, the only other Sound methods that are enabled are Sound.extract() and Sound.play(). Calling any other methods or properties results in an “invalid call” exception. All methods and properties of the SoundChannel object are still enabled.

Anyway, here’s the modified code to use in Lee’s tutorial:

package {
	import flash.display.Sprite;
	import flash.events.*;
	import flash.media.*;
 
	public class soundTest extends Sprite {
		private var sound:Sound;
		private var noise:Number = 0;
 
		public function soundTest():void {
			sound = new Sound();
			sound.addEventListener(Event.SAMPLE_DATA, onCallback);
			sound.play();
		}
 
		private function onCallback(e:SampleDataEvent):void {
			for (var i:int = 0; i < 8192; i++) {
				noise += (mouseX * mouseY) / 44100;
				var sample:Number = noise * Math.PI * 2;
				e.data.writeFloat(Math.sin(sample));
				e.data.writeFloat(Math.sin(sample));
			}
		}
 
	}
}

Have fun!

  • Meta