mardi 27 avril 2010

Flash Scripting Primer, intro and basics

FLASH:
  • Flash can be used as a design tool totally not using script.
  • Flash can be used as a scripting environment, totally ignoring timeline and design features.

In this course we introduce you to the scripting aspects of FLASH.

Main subjects of this course:

  • MovieClip, a structure
  • Events, triggering things from the user
  • Timer, triggering actions from the program
Events:
  • Keyboard event
  • Mouse event
  • Camera event
  • Microphone event
Actions Window

Where do we find the place to do a bit of coding? In the basic scripting window called Actions:

(In Dutch; "Handelingen" )

here is a textfile of the first scripting commands we use:

http://www.contrechoc.com/flash/flash-coding.txt

But first we have to get used to the scripting environment, and we start with our big friend "trace". The command trace prints what you give it into the 'output' window. Trace is a help if something is wrong, if you have to "debug".

Examples: Just in the Actions Window:

trace("hello");

CMD ENTER (for MAC) CTRL ENTER (for Windows) gives:

hello in the output window.

trace( 5 + 4);

gives: 9!

The difference are the quotes....when you do trace("5 + 4");

it gives: 5 + 4

...........

Explore the textfile in the last link, it is filled with all kind of examples, do it line for line, do the typing yourself, that helps for later.

you can copy and paste it into the action window and look what happens, but then you have to know how to make it into a .swf movie.

Exporting a Movie:

Press the CTRL ENTER for exporting the movie as a .swf file.

Try to understand what is happening and try to get used to the strange way the code is written.


Now we go to some prepared movies:

The first example movies can be found here:http://www.contrechoc.com/flash/flash-basics.zip

(CS3 examples made in Flash CS3 also working in Flash CS4)

the basics:

a sound loading example

an image loading example

the scripts are small, and can be copied and pasted into other scripts, (be careful though!)

a sound folder and a banana are joining the party.

(added also: a framelabel example, good start for alternative presentations.)

a great site for FLASH examples (tutorials, also photoshop things) is http://www.smashingmagazine.com/2007/10/30/65-excellent-flash-designs/

Sounds: FLASH handles only .mp3 ,free sounds can be found at: http://www.freesound.org/

images/cartoons can be found everywhere, google images with the keyword “cartoon” and “rabbit” for instance, also this kind of site can be found easily: http://www.barrysclipart.com/barrysclipart.com/index.php

FLASH games? There are about three trillion to be found, but this is a great site: http://www.flash-game.net/

mercredi 10 mars 2010

Buttons and backgrounds texture generator

Doing scripting and coding is already a lot of work. But then, if you don't have a designer at the other side of your desk, you also have to do the imagery. So when you need a sketch you do it the easy way and search for free material on the internet. Just found an easy way of making sketches for buttons…..

http://www.grsites.com/

very nice for some fast menu productions in games….

Here an example of a background used for a flash blocking events example: (text added in photoshop)

this is a button i made for another blog:

this button is for a blog I maintain for a course on nds (nintendo ds) programming, interested? Be careful: this is for NERDS!

http://iepro.wordpress.com/2010/01/14/making-images-buttons-and-backgrounds/

FLASH: usefull links to start coding

We start with a bit of coding in the basic scripting window called Actions:






here is a textfile we use:

http://www.contrechoc.com/flash/flash-coding.txt

you can copy and paste it into the action window and look what happens. Try to understand or try to get used to the strange way the code is written.

The first example movies can be found here:http://www.contrechoc.com/flash/flash-basics.zip

(CS3 examples made in Flash CS3 also working in Flash CS4)

the basics:

a framelabel example, good for alternative presentations

a sound loading example

an image loading example

the scripts are small, and can be copied and pasted into other scripts, (be careful though!)

a sound folder and a banana are joining the party.

a great site for FLASH examples (tutorials, also photoshop things) is http://www.smashingmagazine.com/2007/10/30/65-excellent-flash-designs/

Sounds: FLASH handles only .mp3 ,free sounds can be found at: http://www.freesound.org/

images/cartoons can be found everywhere, google images with the keyword “cartoon” and “rabbit” for instance, also this kind of site can be found easily: http://www.barrysclipart.com/barrysclipart.com/index.php

FLASH games? There are about three trillion to be found, but this is a great site: http://www.flash-game.net/

FLASH: dressup - dressoff

This is an example of a student project, which was made interactive using simple FLASH scripting: (pictures used and published with permission.)

http://www.contrechoc.com/flash/dressupoff/dressupoff.html

(move the mouse over the images and watch the movie go forwards and backwards and change the speed of showing the images)

so: this is a sequence of images which can be played forwards and backwards using the mouse.

the script can be found here: (only the movie for the script,the folder “images” has to be added…)

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

used:

a timer: (to get the images loaded)

var clickTimer:Timer = new Timer(200);
clickTimer.addEventListener(“timer”, functionToDoWhenTimerFires);
clickTimer.start();

a mouse event, (to change the speed of the timer, property timer delay and to change the timer frequency)

stage.addEventListener( MouseEvent.MOUSE_MOVE, changeTimerDelayAndDirection);

for the rest only loadImages is used….

mardi 9 mars 2010

FLASH: the mouse

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 very complex thing! All kinds of events are possible.

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);


So 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: order and chaos

Order and Chaos this time! Nothing more beautiful for an artist. We work with the Math.random function to get random Numbers. And we work with a double for-loop to get order.

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

We need the timer for taking care of the order of the images which are coming in, being loaded.


FLASH, webcam and microphone activity

Today we will be fooling around with webcam and microphone. The webcam can trigger loading of images and playing of sounds etc, so can the 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 found here:

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

used:

  • webcam activity: eventlistener
  • microphone activity: eventlistener