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....

mercredi 15 juillet 2009

Flash final: let your eye’s rock and roll!

As a last item in this short intro in FLASH scripting i asked a cat to let her eye’s roll a bit in a FLASH script…

And other nice simple things. We increase the complexity of the script in this folder.

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

as special features connections of FLASH with other media will be shown, such as:

  • FLASH wii remote connection
  • FLASH rfid connection
  • FLASH PS2 connection
  • FLASH arduino connection….

showing one of the possible next stages of working with FLASH, the communication with the outside world!


Where to go on?
First of all, when familiar with these possibilitities, you could learn to script more structured, in classes. That is quite a jump!
Then you can program top down, that is you can make a scheme of what to do, like

startup
game
highscore
finish

then detailing top down like:

game:
level1
score
level2
score
level3

level:
let shooter come in
let items to be shot fall down
when shooter is killed
new life
when 5 lives are up
loose
when items are shot
next level

then game is a class
gamelevels are a class
shooter is a class
items is a class
score is a class
etcetera

This way you can handle bigger structures like games.
Have fun! Make nice things!

Zooming Drawing and Rippling in FLASH

Today we will study a simple way to get animation from mouse click and movement on Stage.

Three examples: a drawing example, a zooming example and a special effect, the water ripples, this last is using an external script.

the example movies can be found here:

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

as usual we will practice the examples!