jeudi 25 novembre 2010

Using a custom made media template

We will use these templates in practicing programming techniques like using a timer, using an eventListener, in combination with progressive downloading of image, sound and video, :


This folder contains an example with a timer, a sound on keyboard input, an image on keyboard input and the same with all media and video.

With the programming experience of the first blog we will modify the script and make a story using the media variables, like sound, image, and video.

This  example is the media (sound, image, video on keyboard input) template on it's own:

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

We import classes to load an Image and read a Sound (and play it directly).
When we know how to use the classes we dont have to comprehend anything about how this functions.

How to use a class?
first import it:
import LoadImageInMovieClip;
then declare a variable of this class (that is prepare the memory for it.)
giving it parameters:
var myMovieClipWithCarImage : LoadImageInMovieClip = new LoadImageInMovieClip( imageName);
The imageName is a parameter and you have to know that you have to give the name of the image. This image must be in the folder called Images.

Then using this imageClip: putting it on stage
stage.addChild(myMovieClipWithCarImage);

and then later on, removing it from stage:
stage.removeChild(myMovieClipWithCarImage);

or repositioning it:
myMovieClipWithCarImage.x = 500;

The next example is sound:
import PlaySound;

var mySound: PlaySound = new PlaySound(nameOfSound, numberOfTimesPlayed, volume);
these last 3 parameters.....you have to know them..for instance the volume has to be between 0 and 1.
var mySound: PlaySound = new PlaySound("1.mp3", 3,.5 );

and that is all there is to using the classes.

The video is more complicated in the example:
I have prepared the way for multiple video's, putting the video's in an array. These video's have no names, I call them with the place they occupy in the array. The first place is called 0!
(This is always true in programming.)

But lets say you want only one video:

import NetConnectionVideoClass;
var myVideo: NetConnectionVideoClass = new NetConnectionVideoClass("MOV00948.flv");
there are a lot of functions for a video!
stage.addChild(myVideo);//putting it onto stage.
myVideo.addVideoChild();//starting the stream (the naming can be improved!)
myVideo.loopPlayVideo();
myVideo.pauseVideo();
myVideo.resumeVideo();
myVideo.videoAlpha(whatTransparency);// between 0 and 1
myVideo.videoRot(numberOfDegrees);
try it out!

As an extra assignment, I have made a class, TransformImage, which can blend one image into the other, learn how to use it without any understanding!

import this class: 
import TransformImage;

You have to make a MovieClip, add this thing to the Stage.

var myMovieClip5: MovieClip = new MovieClip();
stage.addChild(myMovieClip5);

Then create an instance of TransformImage: (with parameters, this MovieClip, and the names of the images.)

var myTransformMovieClip : TransformImage;
myTransformMovieClip = new TransformImage(myMovieClip5, "car1.png","car2.png" );

and look how image 1 is transformed in image 2.

The images have to be placed in the folder images as usual
You need the class don't you? (It is also in the folder with the examples)
put it in the folder where the flash .fla is, otherwise your .fla will not find it and complain.

Aucun commentaire:

Enregistrer un commentaire