Archive for the ‘actionscript’ Category

Flash + Papervision 3D + Arduino

Monday, March 24th, 2008

In my second little project today, I modified the circuit I built for the Flash etch-a-sketch, by adding another potentiometer and 3 LEDs, each of which represents the voltage of each pot (using pulse-width modulation to ‘dim’ the LED).

Each pot is responsible for either the pitch, yaw, or roll of a cube in PV3D.

Simple stuff that’s been done before! I think I need to think of something a bit more interesting now :D

Flash + Papervision 3D + Arduino

Flash + Papervision 3D + Arduino


f

Etch-a-sketch using Flash and Arduino

Sunday, March 23rd, 2008

Well, I had nothing much better to do today, so after sorting out my previous problems with Arduino and Flash, I thought i’d connect 2 potentiometers to the Arduino board, and make….. Yezzer-sketch!

Here’s the on-screen result:
Yezzer - sketch. Using Flash + Arduino

The very simple circuit:
Yezzer - sketch. Using Flash + Arduino

Video:

I need to get some better potentiometers, these are pretty rubbish.

Yey for making … stuff! :D

Getting Flash and Arduino talking, and problems with AS3

Sunday, March 23rd, 2008

Over the last year, i’ve heard a lot about Arduino, so I was quite gutted when I missed out on both the Arduino talk at BarcampBrighton2, and also on the Arduino session a few days later at FlashBrighton!
Nevertheless, I had to get an Arduino board and start experimenting. Jo had a few Arduino boards, so kindly dropped one round for me.

For me, the most interesting aspect is using the Arduino in conjunction with Flash, sending and recieiving data betwen the two. I realy like the twitter > flash > arduino > LCD display that Mario made. I found it quite inspirational.

Getting Flash and the Arduino talking is initially very, very easy. It takes no time at all to initially write your first “hello world” app - in this case a blinking LED. After that, I turned my attention to reading the output of a potentiometer, and display that in Flash. Again, this is very easy, espically when people have done it already, and you can copy and paste their code! Thanks Beltran, Brett, and Aral for sharing your code!
In no time I had a potentiometer controlling the brightness of an LED, and the Arduino writing the data to the serial port, which Flash was trace()ing to the output window.

Nothing’s that easy though, right? Indeed. I’m expecting values between 0 and 1023, and specifically in this instance, around 1023. This is what I got:

15:37:53:104 = 102
15:37:53:135 = 3
15:37:54:104 = 1023
15:37:55:119 = 1023
15:37:56:135 = 1023
15:37:57:119 = 102
15:37:57:135 = 3
15:37:58:119 = 1023
15:37:59:135 = 1023
15:38:0:151 = 1023
15:38:1:135 = 10
15:38:1:151 = 23
15:38:2:151 = 1023

How strange. As you can see, occasionally the output is split over more than one line. It also does the same on my laptop.
After a lot of hair-pulling, I’ve made a couple of examples, which you can test if you wish. You’ll need to change the port to the one serproxy (or equivalent) is set up to use.

Arduino code:
[code]
void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(”hello”);
delay(100);
}
[/code]

Actionscript 3 code:
[code]
import flash.events.*;
import flash.net.Socket;

trace(”__AS3 Example__”);
var socket:Socket = new Socket(”localhost”,5335);
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
function socketDataHandler(event:ProgressEvent):void {
var now = new Date();
trace(now.getHours()+”:”+now.getMinutes()+”:”+now.getSeconds()+”:”+now.getMilliseconds()+” = “+socket.readUTFBytes(socket.bytesAvailable));
}
[/code]

Actionscript 2 code:
[code]
trace(”__AS2 Example__”);
var socket:XMLSocket = new XMLSocket();
socket.connect(”localhost”,5335);
socket.onData = function (data) {
var now = new Date();
trace(now.getHours()+”:”+now.getMinutes()+”:”+now.getSeconds()+”:”+now.getMilliseconds()+” = “+data);
}

[/code]

AS3 Output:

12:10:43:140 = hello

12:10:43:234 = hel
12:10:43:250 = lo

12:10:43:359 = hello

12:10:43:453 = h
12:10:43:453 = ello

12:10:43:562 = hello

AS2 Output:

12:11:25:406 = hello

12:11:25:515 = hello

12:11:25:625 = hello

12:11:25:718 = hello

12:11:25:812 = hello

12:11:25:921 = hello

AS3 has odd output, and AS2 has the expected output. It’s almost as if ProgressEvent.SOCKET_DATA is called too frequently?
I’ve looked at this, which may be a similar problem. Here’s my post on the Arduino forum which I wrote as I experienced the problem.

In the end I found AS3Glue, which “is an ActionScript 3 library that enables communication between Flash/Flex/AIR applications and Arduino boards”. This changes the way in which AS3 and the Arduino communicate, and fortunately solves the problem described above.

If you use AS3glue, you’ll also need to use the Arduino Firmata firmware. The firmware page also briefly mentions:

It turns out that the USB-serial drivers are optimized for fast bulk data transfer, and those optimizations actually wreak havoc with the timing of the messages over the USB-serial.

Perhaps that’s the problem i’ve experienced? If I can, i’d like to find out exactly what’s going on, but for now, as3glue will suffice :) If you can, please have a test and let me know if you get the same output!

Bow Street Runner

Thursday, February 21st, 2008

I’ve been insanely busy at work recently, working on a huge Flash game for Channel 4. I’ve kept schtum about it all, with only a few hints to what’s been going on to the outside world.

On the 11th Feb, Channel 4 released a preview of Episode 1 to the world, and it’s been picked up by the blogosphere. My favourite moments so far have been seeing my dead body on the front page of Kotaku, and seeing my fat arse on the front page of my favourite site BoingBoing.

To my fellow programming friends, it’s all ActionScript 3, and no, I didn’t do the entire thing by myself ;)

Be warned, there’s a few bugs in this *preview* release. Oh, and there’s 4 more episodes to come in the very near future.

To show the grandkids, when i’m grey and old:

BoingBoing

Bow Street Runner

Kotaku

Bow Street Runner

Team Littleloud rocks!

Welcome to Boston - Flashforward

Wednesday, September 19th, 2007

Well we’re here! And Boston really is a lovely place. Thanks again to D+D for sending us!

I’ll upload pictures to Flickr throughout the week, and i’ll blog whether we win the award tonight!

We’re going to Flashforward in Boston!

Sunday, September 16th, 2007


Littleloud are sending Paul and me to Flashforward in Boston, where we’ve been nominated for the Game award! Yey! Fingers crossed.

Last time we were nominated for an award we won it!

I’ll post a few updates on here while i’m over there, and also i’ll update Twitter

Wonder what good things there are to do in Boston?

Flash developers don’t know the web?

Saturday, May 12th, 2007

Well, that’s what Aral says. Personally, I disagree!

He asks:

  1. Do you know what a mashup is?
  2. Have you ever created a mashup?
  3. Do you know CSS?
  4. Do you use webmail regularly?
  5. How many social networking sites are you on?
  6. How many web applications do you use on a daily basis?
  7. Do you subscribe to RSS feeds?
  8. Do you use SWF Object or UFO?
  9. If you answered yes to the question above, do you know why you use SWF Object or UFO?
  10. Do you blog?

My reply is here. and while I was writing my reply, I saw this on Aral’s site. How web 2.0…

Proving Aral wrong

Looking for the ultimate text editor

Thursday, May 3rd, 2007

After talking to Del about jQuery and editors with intelliSense, I thought i’d take a look at Aptana - “a free, open-source, cross-platform, JavaScript-focused development environment for building Ajax applications”. While downloading this, it occurred to me that I currently use 4 different text editors, and really, I could probably just use one. After all, it’s just text!

I currently use the following editors: Notepad++ (for PHP and editing scripts when I dont want to fire up a full-blown IDE to eat system resources), HomeSite (for XHTML, CSS, JS,ASP), FlashDevelop (for Actionscript), and IDLE (for Python. So rarely do i use this i’ll forget about it for now).

Here’s a short write-up for each editor i’ve been reviewing and their good and bad points:

Notepad++

Lightweight editor, supports multiple languages, extremely fast to load up. Missing some features like a file browser and (s)FTP. Overall very impressed. £Free

HomeSite

I dont think this has been updated for years. I’m using 4.5 which was released in 1999-2000! That IS old! Still, it works reasonably well, with an integrated IE browser, and supports multiple languages. I’d really like to get away from using Homesite. £102

FlashDevelop

I used to use SEPY for editing Actionscript, but something drove me towards FD instead. It’s good at what it does… but of course, it only supports Actionscript, which is a pain. It’s not the speediest editor to load either. £free

E- TextEditor

The Windows equivalent of TextMate. Reasonably fast to load, and supports multiple languages through the use of TextMate bundles. I haven’t managed to get it working with the Actionscript bundle yet :( There’s a good screencast on their site which is worth watching. TextEditor has the most amazing feature i’ve seen so far: Select multiple areas of text, and then start typing. Watch the screencast to see it in action: I think it’s amazing! $35 per year.

Aptana [screenshots] [videos]

I really like this open-source editor. It’s extremely good for XHTML, CSS, and JavaScript. It’ll even show you which browsers support different properties. It supports (s)FTP. No support for Actionscript yet though :( Slow to load, but worth it. It’s built on Eclipse, yet I find it easier to use than Eclipse. £free

Eclipse

From it’s credentials Eclipse should be the best editor out there. At the moment I find it impenetrable and unintuitive. If someone who uses it regularly spent an hour guiding me through it, i’d probably get on with it better, but until then, I can’t consider it an option. A shame as it’s free, and via the enormous amount of plugins available, it supports all the languages I need! £free

Conclusion
Well, I can’t draw a definitive conclusion on this, as i’ll continue evaluating more text editors, and hopefully one day I’ll learn to live with Eclipse. It’s got to be the way forward, as it’s so powerful, and its available for Windows, Mac, and Linux.

For now? I’ll continue using Notepad++ for quick and easy editing of most files, and use FlashDevelop for Actionscript. I guess the only change will be using Aptana for web development. Perhaps that’ll help me get into the Eclipse IDE as well.

getURL() not working

Monday, April 23rd, 2007

I was taking a look at ThickBox earlier, and having a nose around calling it from Flash. To do this, I needed to call JavaScript from flash.

Although if you’re using Flash 8, you should probably use ExternalInterface, the quickest way to do this is by calling:
[as]
getURL(”javascript:functionName(param1,param2)”)
[/as]

It’s been a while since i’ve needed to to do this, and it just wasn’t working on a simple test. Even simplifying this wouldn’t work in either Firefox or IE:

[as]
getURL(”javascript:alert(’hi’)”)
[/as]

Turns out it works fine when the content is served through a webserver.

Also, after reading one of Mike Chambers posts, I found you can run this locally, if you put this in your object and embed tags:

[html]
allowScriptAccess=”always”
name=”allowScriptAccess” value=”always”
[/html]

Of course, this has other implications, so best not to do this unless you know what you’re doing.