Posts Tagged ‘AS3’

How to Read a Binary Watch

Wednesday, August 11th, 2010

The Flash plugin is required to view this object.

A while ago, I received a Binary watch as an anniversary gift. Since then, I frequently get asked how I read it. So let me break it down for you.

First, note the Flash app to the left. I built this for my Chumby, but the inspiration came from my watch. The main differences are that I put in a line of bits to show seconds, and I gave it the ability to show the date. Tap the watch face to view the date for five seconds. If you’re reading this, 01 The One, take some notes.
(more…)

Duplicate MC in AS3

Thursday, July 15th, 2010

The Flash plugin is required to view this object.

So, the other day I was looking for a way to duplicate a movie clip that the user clicks on. In my case, I had lots of buttons made of the MCs that I wanted to copy. I could have made a big switch statement like this:


(more…)

Database access with a Chumby

Thursday, May 6th, 2010

Chumby, Database AccessIn my earlier posts, I’ve writen about writing a Chumby widget, writing a configuration widget, and accessing the accelerometer. Now we’ll look at accessing a database from a Chumby widget.

First, you’ll need to set up a database. I’ll assume you have access to a web server and know how to create a database, tables, and code to access it. I use MySQL and PHP.

You’ll also need a Chumby widget.

And to connect the two, you’ll need a crossdomain.xml file.
(more…)

Accessing the Chumby Accelerometer

Friday, March 26th, 2010

Chumby Accelerometer
Let’s take a look at the Chumby accelerometer. It’s the thing inside Chumby that tells it if it’s looking up or down, sideways, or up-side-down. It also detects sudden changes in acceleration. It’s basically an electronic inner ear. So if you shake Chumby, knock him on the side of the head, or drop him on the floor, the accelerometer will detect this and report how hard and in what direction the jolt happened. Disclaimer: I do not recommend or endorse violent behavior to Chumby, including hitting, shaking, throwing, or dropping.

If you’re familiar with Actionscript, you know that it’s pretty easy to find the position of the mouse cursor on the stage. Well, it’s also easy to get data from the accelerometer. The trick, however, is making use of it. Let’s take a look.
(more…)

More Fun With Flash

Monday, March 22nd, 2010

The Flash plugin is required to view this object.

Here’s a little thing that I wrote a while ago while learning the Flash particle system.  It just makes little light blurbs generate from your mouse pointer.  It’s pretty neat, and if you don’t know how to generate particle effects in Action Script 3, the code might help you out.  Check it out if you want to.

If you find it helpful or fun, let me know in the comments.  Thanks for reading!  Code when you click through…



(more…)

Creating a Chumby Configuration Widget

Friday, February 26th, 2010

In my last post, we quickly went over Writing your first Chumby widget. This time, we’ll expand on that by adding a configuration widget.

A configuration widget is another Flash file that sets up parameters for your Chumby widget, so those settings are available when the widget loads into your Chumby. For example, perhapse you have an analog clock widget. You could create a configuration widget that allows someone to choose a color for the face of the clock, or whether or not to display the second hand. The user could choose a color and save their preferences in the Chumby database. Then, when their Chumby loads your clock widget, it would look for and download any settings for that widget.

Here’s what we’ll need:

(more…)

Writing your first Chumby widget

Monday, February 1st, 2010

tic-toc-goes-the-clockSo, you got your first Chumby and have browsed through the 1500 open source widgets, and now you’re ready to contribute to the open source community by writing your own widget. There’s lots of resources out there, so we’ll just cover the basics here.

Here’s what you need:

  • A Chumby
  • Adobe Flash or other developing environment for creating SWF files
  • An account at Chumby.com

Open up Flash. Set your size to 320 x 240 and frame rate to 12 frames per second. In Publish Settings, set the Player to Flash Player 8 and the Script to ActionScript 2.0. Chumby allows widget up to 100kb in size, which is plenty of room for code, but can get tight when working with audio and video.

For this tutorial, we’ll make an analog clock. But there are hundreds of clocks already! Yes there are, but I like to have every other widget be a clock, and I’ve only found about a dozen clocks that I really like. That is one of its primary functions, after all.

First of all, set up your assets. You’ll need three clock hands, positioned in the center of the stage, with the registration point properly set. Name them hourHand_mc, minuteHand_mc, and secondhand_mc.

OK, now the code:

onEnterFrame = function() {
	dt = new Date();
	//set hour hand
	hrs = dt.getHours()+dt.getMinutes()/60+dt.getSeconds()/3600;
	angle = hrs*30;
	if (angle!=hourHand_mc._rotation) {
		hourHand _mc._rotation = angle;
	}
	//set minute hand
	mns = dt.getMinutes()+dt.getSeconds()/60;
	angle = mns*6;
	if (angle!=minuteHand_mc._rotation) {
		minuteHand _mc._rotation = angle;
	}
	//set second hand
	scs = dt.getSeconds();
	angle = scs*6;
	if (angle!=secondHand_mc._rotation) {
		secondHand _mc._rotation = angle;
	}
}

Let’s break it down. On each frame we create a new date object. Then we get the hours of the date object. We also add in the minutes and seconds because we want the hour hand to move a tiny bit every second, not just once an hour. Next we convert the hours into degrees by multiplying by 30. (360 degrees per 12 hours makes 30 degrees per hour). Next we check if the hour hand needs to be changed. It should only be changed once every 12 frames, not every frame. Using this if statement prevents unnecessary redrawing of the screen, which can save processing time and make a widget run more smoothly. Though, you’ll probably not notice any difference in this simple example.

The minute hand and second hand go through the same process.

OK, save it, publish it, and upload it to Chumby.com, but don’t make it public yet. Add it to a channel on your chumby and try it out. You’ll undoubtedly find lots of things to tweak with your clock. Did you even give your clock a face? Maybe it needs a tick sound, or a gong on every hour. Maybe you don’t want a typical analog clock. Changing the code for a digital clock should be pretty easy.

This is a simple example, but it should get you on your way. In my next post, I’ll write about creating a configuration file, and playing with the accelerometer. (unless I forget or change my mind). Until then, make a cool clock.

The Problem with Probability

Friday, January 22nd, 2010

If you were to flip a coin 10 times, and it comes up heads each time, you might think, “On the next flip, it’s SURE to come up tails – it’s due.” If you flip the coin 10 more times and again it comes up heads each time, you might think, “The next flip will surely be HEADS. Just look at the statistics.” Of course, we know that any flip has just as much chance as being heads as it does tails (assuming the coin is evenly weighted and symmetrical). So how many flips does it take to change our feeling about the next flip? Somewhere between 10 and 20 flips? (more…)

Flash Camera

Monday, December 14th, 2009

The Flash plugin is required to view this object.

On a recent project (which will be revealed later this week) we needed to save an image created in a Flash application, using AS3 and PHP. It turned out to be really easy. Here’s how we did it…

(more…)

Stopwatch for Cubers ver 2.0

Thursday, December 3rd, 2009

What do you know? I did get around to updating my timer. Introducing Cube Clock 2.0 for Rubik’s Cubers (and other cubes) with fancy new graphics, sounds, and a settings screen. See Stopwatch for Cubers for the original version.

The Flash plugin is required to view this object.

If you want to study your cube before the time starts, click the SETUP button to specify how many seconds you would like to study. The default is 0 which means the time starts as soon as you release the space bar (or click the START button). You can also toggle sounds on or off.

Let me know if you would like to see any features in the next version. And, of course, post your times in the comments.

Cube Timer v2.0 Source (FLA)