mercredi 17 février 2010

FLASH scripting starter 2

After discovering your truly great friend "trace" in FLASH and some other commands we go on loading an image and a sound.

We do this streaming, loading the sound and the image from outside the FLASH movie.

The details of this streaming is hidden in a function which you can copy from the example script. You dont have to study this!

What we will practice is making your movie listen to the keyboard and loading images and sounds from the keys.

For this I have made a collection of ready to use sounds:
http://www.contrechoc.com/flash/shortMP3sounds.zip

The image have to come from your own collection, you can use JPG or PNG.
PNG can be transparent.

We use this example movie:

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

We will explore this  movie and make it our own, that is to say we will make our own interactive FLASH movie, importing sound and images.

used:

  • keys, keyboard, keyListener

FLASH scripting starter 3

Order and Chaos this time!

Loading a sequence of images in a for loop.
We learn how to put the timer to good use:

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

I promised you the MouseEvent, here is a drawing movie illustrating the different event playing together.


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


The mouse is a complex thing!

Here are several eventlisteners for the mouse:

  • addEventListener(MouseEvent.CLICK, clickHandler);

  • addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler);

  • addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

  • addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);

  • addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);

  • addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

  • addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);



A mouse is more complex than a key!
for instance the position, which can be  found using the event like this:
function startDraw ( event:MouseEvent): void

{
var posX : Number = event.stageX;
var posY : Number = event.stageY;
}

used:

  • for loop

  • timer

  • mouse event (in simpledraw)

FLASH scripting starter 4: let's have fun

Today we will be fooling around with webcam and microphone.

Later on we will discover how to load streaming movies. (needed flv format: use Media Encoder of Video Encoder

The examples can be found here:

http://www.contrechoc.com/flash/flash-fun.zip

To get some streaming movies we could try to download movies in flv format from youtube.

If nothing is playing or the mic does not respond, first verify if the computer has a mic or webcam, and then try clicking right in the flash window and look at the settings.

ways to download from youtube can be fund here:

http://www.frankwatching.com/archive/2007/05/08/top-25-hoe-download-ik-een-youtube-video/

FLASH starter: ripple effect

[We will be busy doing the asignment during these weeks, but interesting things will be shown anyway:

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

This is the ripple effect, which can be put on a movieclip.

Nice for water effects, but also for imagining dreams!

Remark:

Some of my students (Kevin Klein) in Leiden used this effect but got in troubles using the Full Screen Mode: the framerate was severely reduced: he found the solution:

in settings (right click on the movie) uncheck hardwareprobleem.jpg acceleration : here the picture with the settings window...

Thx Kevin!

Flash Scripting: temporarily blocking events

Hi all, there was a question how to prevent images coming in too fast, for example if images are loaded on webcam activity.

The principle is to use a timer to get the delay.
The timer starts and a blocker is put in between the events coming in and the loading.
After the timer has expired, the blocker is removed.

You can use a Number as a blocker, using 0 and 1 for example but  here we use a Boolean.

A boolean can only be true of false (0 or 1).

var stoppingEvents:Boolean = false;

we use a delay timer, when it starts events will not cause reactions:

var delayTimer:Timer = new Timer(1000); //timer delay is 1000 milliseconds
delayTimer.addEventListener("timer", goOnListening);

This is how we stop events:

function keyDownHandler ( event:KeyboardEvent ): void
{
if ( stoppingEvents == false )
{
if (String.fromCharCode( event.charCode) == "1") //the active key is "1"
{
readSound("1.mp3");
stoppingEvents = true; //blocking the next 1000 milliseconds any sounds
delayTimer.start();//count down to give the listener free
}
}
}

we have started the timer here, when it is done:

function goOnListening (event:TimerEvent ) {

stoppingEvents = false;
delayTimer.stop(); //stopping th timer
}

it removes the blocker....

here is the source code:

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

of course this example can be used for blocking mouse events, webcam events, microphone events just as easy....