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 Flash Engineer PopCap Games, International Ltd.

Portfolio

UV Scrolling in Starling


Obviously this could come in pretty darned handy for space games, side scrollers, etc, etc[...]

Drawing on Stuff in Away3D 4.0

So, Easter Day, I thought I’d sit down and make a little ‘Paint on an Egg and Send it to Your Friend’ app.

Santabot: A Unity3D Flash Game


All right, so a Christmas game like “Santabot vs. The Flying Saucers from Mars” may be a day late[...]

Magnify – a jQuery Plugin


Let me begin by saying right up front, I have not given up on Flash[...]

It’s a Starling Halloween


Getting some practice for the upcoming Zombie Apocalypse[...]

Getting Started with Proscenium

So I had a chance this weekend to sit down and play around with Adobe’s new 3D framework for Stage3D, Proscenium, and thought I’d share a few of the results (a word of caution, there are no preloaders for any of the examples and may load a bit slowly). The first shows some reflections and [...]

Particle Editor for Starling Framework

An in-browser particle editor for the Starling 2D Framework for Flash Player 11.

So Long and Thanks for all the Flash on the Beach

So, another Flash on the Beach has just has just drawn to a close[...]

Game Development Tips from the Trenches of PopCap

Well, this is a post that’s a bit overdue, but, thanks to a well timed bank holiday, I finally had the opportunity to sit down and type up what I’ve been meaning to for some time now…

Old Skool Demoscene FX as 3D Textures

Many moons ago, I got the idea to create some demoscene plane deformation effects in Flash based on the formulas found here: http://www.iquilezles.org/www/articles/deform/deform.htm. I posted my less than desired results up on wonderfl. Thankfully, fellow wonderfl user, Hasufel, forked my attempt and optimized the hell out of it coming up with this. Well, today, for no [...]

Making The Gaming Scene (A Change in Careers)

And for my second blog post of the day, a much more personal note. After about three years of working with, what I would consider as objectively as possible, the best digital agency in Ireland, vStream Digital Media, I have made the immense career decision to leave the agency world and enter the arena of [...]

Feeling Lucky?

Images to dice, kick ascii style [...]

Adventures in Playbook Land

Adventures in Playbook Land


Now that the ordeal is over, I thought I’d take the time to sit down and share my account of what it was like to develop a Blackberry Playbook application using the Adobe Flex SDK[...]

Flash

Draw it for Me

So many ideas – so little time….

Kinect Application Running in Dublin

So, on Friday I just wrapped up our latest project at vStream Digital Media, a Kinect powered flipbook that lets users flip through the hand written notebooks of Philip Lynott of Thin Lizzy. The app uses OpenNI, runs in Adobe AIR and is currently on display at a pretty bitchin’ Phil Lynott exhibition running in [...]

Beach Ball Kinect Party

So we finally got a Kinect camera hooked up to a pc at work and, while it doesn’t seem to be legal to use it for commercial projects (but, hey, I’m no lawyer), the boss asked me to get it figured out and come up with some ideas just in case it would be feasible [...]