OBO_NumberScrubber – a new UI Widget

I’ve seen ‘em used in After Effects for ages and now they’re a part of the Flash CS4 interface, so I figured why not a new Flash widget. This little UI component allows users to change numerical values by clicking then dragging their mouse to the left and right over the number display. By clicking once and not moving the mouse, the number can be adjusted manually. For a better idea of what I’m talking about, check out the example below:

Get Adobe Flash player

The above example was created with the following document class:

package {
 
	import com.onebyonedesign.ui.OBO_NumberScrubber;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
 
	/**
	 * Quick test of OBO_NumberScrubber
	 * @author Devon O.
	 */
	public class Main extends Sprite {
 
		private var _redSquare:Sprite;
		private var _numberScrubber:OBO_NumberScrubber;
		private var _label:TextField;
 
		public function Main():void {
			if (stage) {
				init(null);
			} else {
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
		}
 
		private function init(event:Event):void {
			initSprite();
			initLabel();
			initScrubber();
		}
 
		private function initSprite():void {
			_redSquare = new Sprite();
			_redSquare.graphics.beginFill(0xFF0000);
			_redSquare.graphics.drawRect(0, 0, 300, 300);
			_redSquare.graphics.endFill();
			_redSquare.x = 50;
			_redSquare.y = 25;
			_redSquare.filters = [ new DropShadowFilter() ];
			addChild(_redSquare);
		}
 
		private function initLabel():void {
			_label = new TextField();
			var fmt:TextFormat = new TextFormat("_sans", 11);
			_label.defaultTextFormat = fmt;
			_label.selectable = false;
			_label.mouseEnabled = false;
			_label.autoSize = TextFieldAutoSize.LEFT;
			_label.text = "Set Alpha:";
			_label.y = 350;
			_label.x = 50;
			addChild(_label);
		}
 
		private function initScrubber():void {
			_numberScrubber = new OBO_NumberScrubber(0, 100, 100, 50, "_sans", 11, 0x000088);
			_numberScrubber.x = Math.round(_label.x + _label.width + 5);
			_numberScrubber.y = 350;
			_numberScrubber.addEventListener(Event.CHANGE, scrubberHandler);
			addChild(_numberScrubber);
		}
 
		private function scrubberHandler(event:Event):void {
			_redSquare.alpha = _numberScrubber.value / 100;
		}
	}
}

You can preview, download, and peruse the documentation of the entire onebyonedesign UI library here.


And in other news… A Belated Merry Christmas to all from the wife and I. Hope the New Year is great for all…

9 Comments »

  1. dVyper says:

    Nice widget! I think the number scrubber should be a little more sensitive though – the value changes a bit too slowly…

  2. Devon O. says:

    Thanks for the comment dVyper. I struggled with that a bit. I wanted an algorithm that would be just as responsive for a range of 0 to 1 as it would be for -1000 to 1000. I’ve changed it since you posted. It may not really be noticeable in the above example, but I much prefer it now. The newer version’s been repackaged on the download page. The download itself’s a bit big, but includes all the docs and crap.. Thanks again.

  3. Og2t says:

    Nice one Devon! I was thinking of writing it myself but wanted to use up/down or mousewheel. Another idea would be to use modifier keys (shift/alt/ctrl) to change the step (0.1/10/100).

  4. Devon O. says:

    Some cool ideas, Og2t.. I might look into them this weekend if I have some time..

  5. chris says:

    Clicking the scrubber and moving the mouse in one direction does exactly what it should be doing. However, switching directions and moving the mouse in the opposite direction produces random results, sometimes not affecting the scrubber at all, other times resulting in major jumps in the value. Try clicking the scrubber and moving the mouse frantically left to right to reproduce this bug.

    Using Firefox 3.0.5, Flash Player 10, on Windows XP.

  6. ed says:

    Yo, I need your help I can’t seem to get this to work on my commodore vic 20. I found one in my mom’s closet I used to play games with the neigheibor kid with, listening to Exit Stage Left, and playing Dungeons and Dragons. Thanks in advance, Ed. :).

  7. Devon O. says:

    Hey ed, did you try “10 CLS 20 PRINT “Devon is cool.” 30 GOTO 20″ ?

  8. ed says:

    I did and the computer started spaming that “I know Devon is cool and Ed is a bone head” It looks like you are doing well, keep up the good work. Your website is very interesting.

  9. Devon O. says:

    Hmmm.. I seem to recall playing on a Vic-20, listening to Rush and playing D&D with a neighbor kid.. Who’d a thunk someone who did all that would turn into such a nerd…

RSS feed for comments on this post. / TrackBack URI

Leave a Reply

Devon O. Wolfgang

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development”

Contributing Author of “Flash AS3 for Interactive Agencies”

Senior Software Developer in Dublin, Ireland

Portfolio

Bayer Pixel Bender Filter

Bayer Mosaic Filter in Pixel Bender


Now, seeing as how I’ve been trying to learn some Pixel Bender coding lately[...]

Liquitext

Liquid Text Effect


Haven’t been too active around here lately due to a major on going project at work lately as well as the fact that my wife and I are in the slow process of moving homes. Really, the only free time it seems I have these days is during the lunch hour. So, over the past two days, I came up with this fun little toy during lunches[...]

Google’s Text To Speech Engine in Flash

I’m not sure how I managed to miss this, but I just happened to run across a ‘new’ (well, newish), albeit still unofficial, offering of Google today: text-to-speech. You can see what few details there are on this Techcrunch post. Basically, it just boils down to this though – you send your phrase to be [...]

Quick Sound Effects Generator


Need some beeps, boops, or bops, to go with your UI or games [...]

Quick QuickBox2D Tip II – Collision Detection

Custom collision detection/handling in QuickBox2D [...]

None of This Runs Eternal


No Flash/Actionscript stuff here. Just me rambling about the upcoming Current 93 concert [...]

Playing Around with the New UndoManager

Included in the Flex 4.0 SDK and the, just released, Flash Professional CS5 lies a new hidden little gem of a class: flashx.undo.UndoManager (although the Flex 4.0 SDK’s been out for awhile, I have to admit I didn’t even notice this until I installed Flash CS5 and started poking around the documentation looking for new [...]

Making Waves

In a previous post, “Digging into the Microphone in Flash Player 10.1″, reader David Law asked in the comments how it would be possible to save .wav files to the server. I wasn’t sure right offhand, but thought I’d spend my lunch hour yesterday looking into it. Well, after reading this quick tutorial on Adobe [...]

Some Drawing Fun and a Bad Movie You’ll Never See

Earlier today, Dave Gillem posted a link on Facebook to an incredible Processing based drawing application. Thought I’d have a go at reproducing something similar in Flash. Well, I failed miserably, but the results were still interesting enough to check out. You can play around with it below. Just mouse down to draw in the [...]

Animating Bezier Curves


The other day I got the notion in my head that I wanted to draw some bezier curves in an animated fashion. I’m sure this has been done a million times before, but sometimes reinventing the wheel can be a good learning experience [...]

My God, It’s Full of Stars…


Just a quick little thing I got an idea for (i.e. pretty much ripped off) while browsing Processing examples.

Another Year, Another Look

As a few folks may have noticed, the blog is looking a little bit different as of today [...]

The Webcam Warholizer


Just a little bit of quick Friday fun with webcam and bitmapata…

More With the JiglibFlash Terrain

Playing around a bit more with the animated JiglibFlash terrain idea from my last post, I wanted to see how it would work in conjunction with a webcam. So, needless to say, you’ll need a webcam to check out the results below.

Rockin and Rollin with the JiglibFlash Terrain


Finally got the chance to play around with the new JiglibFlash height map terrain, today, and have to say I am very impressed [...]