samedi 25 décembre 2010

Handling errors in flash cs3

During a presentation about the universe using a flash movie for showing images and video's i got the error:

Error #2044: AsyncErrorEvent non pris en charge : text=Error #2095: flash.net.NetStream n’a pas été en mesure d’appeler l’élément de rappel onXMPData. error=ReferenceError: Error #1069: La propriété onXMPData est introuvable sur .CustomClient et il n'existe pas de valeur par défaut.

These errors in the middle of a presentation are a nuisance and you want to get rid of them!
(On the other hand the children liked very much shouting ERROR ERROR ERROR!)

There are a few ways to get rid of an error:
first write good code, :-)
secondly, if you expect something to go wrong you can use a try catch structure:

var myNumberWhichCanGoWrong : 10;
myNumberWhichCanGoWrong--;
trace( 1/myNumberWhichCanGoWrong);

Although I even remember that flash catches thiseasy error itself, you can do:


try (
trace( 1/myNumberWhichCanGoWrong);
)
catch(e:Error){
trace("heee!, you are trying to divide by 0!!!!");
}

but sometimes this "try and catch" game does not work, like in this case (of my presentation of the universe to children):
you have a video, but it lackes some XMLData which are expected and when you create a netstream connection, even with try and catch:

private function connectStream():void {
            try {
                stream=new NetStream(connection);
            } catch (e:ReferenceError) {
                trace(e);
            }
            try {
                stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            } catch (e:ReferenceError) {
                trace(e);
            }
            try {
                stream.client = new CustomClient();
            } catch (e:ReferenceError) {
                trace(e);
            }
            addChild(video);
        }

 with this class:
class CustomClient {
    public function onMetaData(info:Object):void {
        //trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
    }
    public function onCuePoint(info:Object):void {
        // trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
    }
}

As you can read in the error above:

Flash expects MetaData and if these are not available and there is no default, this results in an error. And "try catch" does not help...

i found the solution here:
http://www.adobe.com/devnet/flash/quickstart/metadata_cue_points.html

it is adding an eventlistener for this error:
.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

and then handling this error, or ignoring it in the function  asyncErrorHandler

        private function asyncErrorHandler(event:AsyncErrorEvent):void {
            //trace(event.text);
        }


In FLASH cs3 errors are regularly spoiling the fun, this way of getting rid of your errors by eventlisteners is a good tool to spoil the fun of flash trying to irritate you with errors!

And why was I using Flash to present and not powerpoint?
I is just fun programming your own presenter, and also I use flash to connect to my DIY remote controls, see this blog entry about these electronic wonders:
http://myfablab.wordpress.com/2010/12/23/making-a-diy-remote-control-for-a-performance/

lundi 1 novembre 2010

Flash and dataBase (and also connect to Second Life)

Flash can load and write data to a database using the URLRequest in combination with
URLVariables. (using a few php pages of course)
This all seems simple, but as usual there are a few deatails with the way FLASH wants to receive the data loaded from the database.
The data must be arranged in pairs.

I found these links which describe the matter clearly and give working examples:
http://www.flash-db.com/Tutorials/savingAS3/
http://www.flash-db.com/Tutorials/loadingAS3/

You need a database of course and a table.
You can get space on http://byethost.com/

The example of the loading has only two field, so if you want to load more records loaded you have to make for instance one big textfield and insert the records in this field.

To have more fun you can do the same in Second Life, that is writing and loading the dataBase:
http://wiki.secondlife.com/wiki/Http_request
Now you can manipulate objects in Second Life using Flash, or use the Arduino, connected to Flash using a socket to interfer with things in Second Life!

jeudi 3 juin 2010

FLAR marker generating, single and multiple

This example shows how to use multiple markers:
http://www.squidder.com/2009/03/06/flar-how-to-multiple-instances-of-multiple-markers/

The example is very funny, making a piano with appearing and disappearing cubes.
We wanted to show images and a video, the images being changed with a timer.

For this we had to modify the main file:
MultiFLARExample.as in src
where we have started a timer.

This folder structure is different from the single marker Flar Example.

We have modified this size of the flas movie, it now has a bigger screen: 800 x 600.
(These properties have to be altered by hand in rather a lot of files, watch out for the webcam heigth and width, these are also hard coded but at half this size .... so search the folder for 800 and (half of this:) 400 if you want to change the screen width and size.

So there is a timer added in
MultiFLARExample.as in src
The images from the folder triangleImages
in assets
in deploy
are projected on the cubes

and on the fourth cube there is a streaming video

in the function function _addCube(id:int,index:int):void
you can make your own shapes instead of the cubes...

three images (one transparent) and a video projected on a cube


http://www.contrechoc.com/flash/FLARSquidderKitModified.zip

If you want to experiment with this movie first print the markers from the folder deploy/assets/flar

Link explaining making a marker:
http://www.squidder.com/2009/03/05/for-nerds-only-custom-flar-markers-explained/

mardi 20 avril 2010

Flashplayer with Arduino Security problem

Mac OS: Flash CS 4.
We had a presentation using sensors read by a Lilypad. Using serproxy and a Socket we got the data into Flash.
The first problem with the MAC is setting the serproxy.cfg

# Settings for COM: which com port for the MAC??? ( I used TinkerProxy to find out)
comm_ports=3
serial_device3=/dev/cu.usbserial-A6007wFX
net_port3=5333

you have to use the "cu" of the ports indicated by the arduino tools

But using the Flashplayer to go Full Screen we got security violations.
Eventually we found the solution:
in Library/Application Support/Macromedia/FlashplayerTrust
there are files like
kuler.cfg
make another cfg file (copying and changing the name)
and add the location of the trusted file: (like:)
/Users/contrechoc/Desktop/flash scripting results/project_Annet_Clothing_as_Interface/Clothing_as_Interface.swf
then save and try out the stand alone flash movie
it worked for me and if you know the solution it is not too difficult.
(But bumping into this problem just before a presentation is rather stressing...)



Emroidery and design by Lola Khodjaeva, used in the project Clothing as Interface by Annet Couwenberg. We used the Lilypad with four (cheap 10 euro) distance sensors, normally used for parking a car.

vendredi 19 mars 2010

WII remote and FLASH example

After Johnny Lee, we all do the the trick with the Wii remote and Flash.
It is just more fun steering the computer with the Wii than with the keyboard or mouse!

Just using Glove Pie we can easily catch the sensor values of the Wii remote and use these values in FLASH.

For the class Computer Science and Media, I use a wii steering the presentation of the Kick-off of a half year course. I even bought a steering wheel for the wii at dealextreme.com!

This is the file of the flash movie, with scripts and the glovepie script.
Included is also microphone activity and webcam activity, although I turned this off during the presentation :-)
The presentation is done in my old website which was presented inside this beautifull violet nds...

jeudi 18 mars 2010

ARDUINO and FLASH (problems)

The ARDUINO is great for catching input, and FLASH is very convenient for designers to work with. Combining the two is not difficult at all, although there are some details which could be complicated. Or so we thought....indeed sometimes it works, but switching from XP to MAC OS for instance requires the right port setting, and still the serial data, from the analog ARDUINO pins comes in erratically, also changing from the ATmega168 to the ATmega2328 board does seem to change the way the serial data come in.
Using a Socket in FLASH or using an XML Socket differs too...

So there are a few problem areas:
  • the config file for Serproxy, which is the port number in the MAC OS case?
  • the FLASH socket, XML or not?
  • the serial data coming in, sometimes something seems to be skipped, do we have to use a checksum?

There are several links in the Arduino docs explaining what to use and how:
http://www.arduino.cc/playground/Interfacing/Flash
Personally I use simply the Serial lib from the Arduino, Serproxy and a socket in FLASH.
You have to configure the serproxy.cfg, that it uses the right com port. Then you have the two way communication. (Tinkerproxy is only one way.)

Setting the serproxy config file is explained here: http://protolab.pbworks.com/TutorialFlashSetup
Especially for the MACOS fans...

The digital pins work fine, being only true or false.
So you start the arduino script, just talking into the serial port:
like Serial.println (digitalRead(pinNumber));

Serproxy is started, it says waiting for clients...

Then in FLASH you use:
import flash.net.Socket;
you add an eventlistener:
arduinoSocket = new Socket("localhost",5331);
arduinoSocket.addEventListener(Event.CLOSE, closeHandler); arduinoSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);

and you read the data:
var nb : uint = arduinoSocket.bytesAvailable;
var bytes:ByteArray = new ByteArray();
var input:String = String(arduinoSocket.readShort( ));
//or like this
//var input:String = String(arduinoSocket.readBytes( bytes, 0, 5));

the reading of the HIGH or LOW is simple and reliable, but the potmeter on an analog port is more complex, due to the bits being sent through the Serial port which have to be caught in the right way.

basic flash script (will be improved shortly)

Using the analog pins ( a potentiometer or a flex sensor) gives more problems.
You have to experiment with the bytes coming in.

We had the arduino flash connections running on XP using serproxy in no time.

On the other hand we had trouble getting it running on MAC OS. The problem was the comport naming. Apparently normally ARDUINO software choses /dev/tty.usbserial-*, but for Serproxy you need the /dev/cu.usbserial-*
so using this serproxy.cfg:
# Config file for serproxy

# Do not Transform newlines coming from the serial port into nils
newlines_to_nils=true

# Comm ports used
comm_ports=3

# Default settings
comm_baud=9600
comm_databits=8
comm_stopbits=1
comm_parity=none

# Idle time out in seconds
timeout=300

# Settings for COM3
serial_device3=/dev/cu.usbserial-A7006vzH
net_port3=5333

we got it right. Also why is this called port 3? We found that out using Tinkerproxy, which showed this port number, but the list of ports in the terminal gave no clue about this number.

Anyway, now it works on both operating systems....
Well this was what we thought, but experimenting with our own and scripts of other found on the internet, with different ARDUINO boards, with XMLSocket and the plain "Socket" class, we still have erratic data coming in the FLASH part, skipping things etc.

(If you open the serial window in the ARDUINO IDE then the data come in fine.)

Evidently more experience and or knowledge of what is going on is needed.

mercredi 10 mars 2010

OO FLASH starter

Here the source you can find an example of a simple OO structure in FLASH CS3 / 4

It needs an empty FLASH movie with in the properties window setting the class to OOstarter

This OOstarter imports all the other classes it needs.

It just loads an image and a textfield, waits 2 seconds and loads another image and starts moving a small circle around.

the movement is quite bad!

It illustrates the use of classes, and could be the beginning of a wonderful mini golf game.

the source