Tampilkan postingan dengan label flash. Tampilkan semua postingan
Tampilkan postingan dengan label flash. Tampilkan semua postingan

Creating a Rotating 3D Planet in Flash


Here we are taking new flash document with action script 2.0.
Creating Realistic 3D Planet!
Step 1: Setting Up Document Properties
Now Select Modify from the menu bar and select Document or You directly can press ctrl + J to open the document properties.
Creating Realistic 3D Planet!
Now change the stage dimensions as 546×370 and the FPS is 30, as shown in the Figure below. To start with the tutorials download the source.zip file that will provide you with the necessary files to be used in the tutorial.
Creating Realistic 3D Planet!
Step 2: Importing necessary images
First import the downloaded used images from the source. To do that, oto the File menu > Select Import > Select Import to Library.
Creating Realistic 3D Planet!
Step 3: Positioning images on to the stage
Before starting we already have layer 1, now name the layer as bg. Drag the bg image from the library on to the stage.
Creating Realistic 3D Planet!
Align the image to the center of the stage using the align panel. Keep in mind that to align any item to the center of the stage, check on the “Align to stage” check box.
Creating Realistic 3D Planet!
Step 4: Creating the earth map
Now insert a new layer above the bg layer, and name it as Globe.
Creating Realistic 3D Planet!
Press Ctrl + F8 to create a new symbol. Type the name Map and select type to Movie Clip.
Creating Realistic 3D Planet!
You will enter the Map movie clip. Drag the Planet1_map image from the library.
Creating Realistic 3D Planet!
Now copy and paste this map image and place them close to each other.
Then select images and press ctrl + g to group into one.
Creating Realistic 3D Planet!
Align the image to the center of the stage using the align panel. Keep in mind that to align any item to the center of the stage, check on the “Align to stage” check box.
Creating Realistic 3D Planet!
Now press Scene 1 to back to the main timeline.
Creating Realistic 3D Planet!
Step 5: Creating the Globe
Press Ctrl + F8 to create a new symbol. Type the name Globe and select type to Movie Clip.
Creating Realistic 3D Planet!
Now create an oval using oval tool as given in the reference image below:
Creating Realistic 3D Planet!
Open the propertied panel. To open the properties panel, Go to the Window menu > Select the properties. Now go to the POSITION AND SIZE. Break the link by pressing on the link icon. Set the W: 200 and H: 195.
Creating Realistic 3D Planet!
Now insert a new layer below the oval layer and name it as map.
Creating Realistic 3D Planet!
Press the outline icon to see the map below it.
Creating Realistic 3D Planet!
Drag the map symbol from the library on to the map layer.
Creating Realistic 3D Planet!
Here you may see the outline of the oval. Now place the map symbol right aligned to the oval and it should be vertically center align.
Creating Realistic 3D Planet!
Step 6: Creating the map animation
Now select the frame 100 of oval layer and press F5 to insert a new frame. Then select the frame 100 of map layer and press F6 to insert a new key frame.
Creating Realistic 3D Planet!
Press the outline icon of the map layer to see the outline of the map.
Creating Realistic 3D Planet!
Here you will see a line in the center of the map symbol in the outline view. Now move the map symbol to the right side till the center line reach to the right edge of the oval. Do not move the map symbol in the vertical direction.
Creating Realistic 3D Planet!
Now select any frame between the frame 1 and 100 of map layer and create Classic Tween. To do that, right click > select Create Classic Tween.
Creating Realistic 3D Planet!
Step 7: Creating the Globe Animation
Now select the oval layer and apply mask to it. To do that, right click > select mask
Creating Realistic 3D Planet!
Now press Scene 1 to back to the main timeline.
Creating Realistic 3D Planet!
Step 8: Placing the globe on to the stage
Now drag the globe movie clip symbol from the library on to the Globe layer.
Creating Realistic 3D Planet!
Place the globe anywhere on the stage.
Step 9: Finalizing the globe or Apply depth to the globe
Select the globe and open the properties panel. To open the properties panel, Go to the Window menu > Select the properties. Go the FILTERS, and click on the new to apply filter.
Creating Realistic 3D Planet!
Select the Glow from the filters menu.
Creating Realistic 3D Planet!
Set the values,
Blur X = 15, Blur Y = 15
Strength = 190%, Quality = High
color #3366ff

for values, see the reference image below
Creating Realistic 3D Planet!
Again click on the new to apply new filter. Select the Drop Shadow from the filters menu.
Creating Realistic 3D Planet!
Set the values,
Blur X = 50, Blur Y = 50
Strength = 180%, Quality = High
Angle = 0, Distance = 20 px
Inner shadow will be check marked

for values, see the reference image below.
Creating Realistic 3D Planet!
Now press Ctrl + Enter to see you effect. You will find the effect something like this.

Membuat Flash Button

Taukah anda tentang button? Button adalah sebuah tombol yang bisa diclick oleh mouse kita. Biasanya button digunakan untuk memanggil fungsi-fungsi tertentu, serta memiliki tampilan yang berubah ubah sewaktu kita meng-mouseover atau meng-click nya. Nah, dalam tutorial kali ini kita tidak akan membahas tentang fungsi – fungsi ( fungsi disini bukan berarti ‘kegunaan’ lho, tapi sebuah ‘function’ ) melainkan hanya membahas pada tampilan button nya saja.
Screenshot  jadi:
image ilmugrafis
Gambar Flash Button

Berikut Tutorial Flash :
- Langkah 1 : Silahkan buka Adobe Flash anda, di sini saya menggunakan versi Adobe Flash terbaru CS5, anda juga dapat menggunakan CS4, CS3, Flash 8, atau versi lama lainnya.
Berikut screenshotnya:
image ilmugrafis


- Langkah 2 : Langkah pertama, mari kita buat sebuah gambar button seperti di atas. Untuk menggambarnya anda dapat menggunakan Adobe Flash sendiri, Photoshop, Coreldraw, Adobe Illustrator, atau aplikasi lain. Di sini saya tidak akan menggambar, tetapi saya menggunakan gambar button sederhana yang sudah ada di Adobe Illustrator.

“hum, saya sendiri tidak tahu, kenapa sangat minim sekali tool tool untuk menggambar di Adobe Flash, mungkin itu merupakan teknik bisnis sehingga bila kita menggunakannya maka kita memerlukan product Adobe lain yang mengkhususkan pada bidang menggambar seperti Adobe Illustrator atau Adobe Fireworks ^_^ “

Berikut Screenshotnya:
image ilmugrafis
“buka Adobe Illustrator anda dan pilih salah satu button yang sudah ada, drag button ke lembar kerja kemudian copy paste ke lembar kerja Adobe Flash”


- Langkah 3 : Saat kita copy paste ke Adobe Flash maka tampilannya akan seperti berikut ini:
 image ilmugrafis
“akan ada konfirmasi saat proses paste, silahkan untuk lebih mudahnya pilih saja ‘paste as bitmap’ , maka semua layer layer dari AI (Adobe Illustrator akan di merge dijadikan gambar bitmap ).
Sebenarnya untuk membuat animasi yang lebih komplek anda bisa memilih ‘paste using AI File Importer Preferences’ , tapi karena di tutorial ini kita hanya membuat button jadi cukup pilih saja ‘paste as bitmap’


- Langkah 4 : Convert bitmap kita ke symbol. Untuk membuat sebuah flash button di Adobe Flash, maka bitmap yang baru saja kita import harus dijadikan ‘button symbol’. Klik kanan bitmap -> convert to symbol -> button.
Berikut adalah screenshotnya:
image ilmugrafis
Setelah convert to symbol maka pilih ‘button’
Berikut screenshotnya:
image ilmugrafis
“symbol di flash dibagi menjadi 3 yaitu ‘movie clip’, ‘button’, dan ‘graphic’. Karena kita akan membuat button, maka kita harus mengeset symbol kita sebagai button. Bila anda ingin membuat animasi anda dapat memilih ‘Movie Clip’


- Langkah 5 : Anda telah berhasil mengkonvert bitmap kita sebagai button. Nah, kemudian langkah selanjutnya adalah kita akan mengotak atik ‘apa yang ada’ di dalam symbol button yang baru saja kita buat.
Double click button dan akan terlihat screenshot seperti berikut:
image ilmugrafis
“di dalam button kita terdapat 4 buah frame yang dapat kita modifikasi dengan menggunakan ‘key frame’. Pada gambar diatas yang baru terisi hanya frame Up, sehingga saat button di preview maka tidak ada effect  ketika mouse diarahkan ke button maupun ketika button diclick, haduh susahnya menjelaskan, untuk lebih jelasnya silahkan dipreview  control -> test movie ( ctrl + enter )   ^_^ “
Frame Up : untuk button normal ( saat tidak ada event tertentu pada button, misalnya mouse over )
Frame Over: saat mouse diarahkan diatas button
Frame Down: saat mouse diclickan ke button ( click di sini masih dalam posisi ditekan, belum dilepaskan)
Frame Hit: Saat mouse dilepaskan ( setelah click )


- Langkah 6 : Saatnya kita isi frame demi frame button kita.
- Mari kita buat button over ( button berubah saat mouse diarah kan ke button)
a. Klik Kanan frame over -> insert keyframe->setelah insert keyframe pastikan anda masih dalam frame over tersebut->klik object button di frame over-> lihat properties di window kanan.
Berikut adalah screenshotnya:
image ilmugrafis

image ilmugrafis
b. Diatas kita lihat bahwa button di frame over masih bitmap, nah untuk menambah effect saat mouse over maka bitmap ini harus kita ubah menjadi symbol lagi. Symbol di dalam symbol adalah ciri khas product Adobe.
Untuk mengubah sebagai symbol , anda tinggal click kanan->convert to symbol ->pilih movieclip atau button.

c. Kemudian setelah terconvert sebagai symbol ( movieclip atau button ), click button yang sudah terconvert sebagai symbol di frame over tadi, nah window properties sekarang sudah berubah seperti pada screenshot di bawah:
image ilmugrafis
“nah, setelah diconvert lagi ke symbol ( movieclip atau button ) maka ada filters (effect yang akan kita gunakan ), juga ada option option lain yang sangat berguna untuk kita”

d. terakhir, beri effect filter saat mouse over di frame over
click symbol button ->lihat window properties-> click add filter ->glow
silahkan lihat screenshot:
image ilmugrafis
“setelah filter glow muncul, anda tinggal melakukan pengaturan sekehendak anda seperti screenshot berikut ini”
image ilmugrafis
Sekarang kita telah berhasil menambahkan effect glow pada mouse over ( tepatnya di frame over ), bila anda ingin mempreviewnya bisa mengclick  control -> test movie pada menu atas.
Berikut adalah hasil akhir untuk button over:
image ilmugrafis
Untuk button down dan hit adalah sama saja prosesnya. Anda dapat berkreasi sendiri, coba coba ,
Maupun membuat sebuah proyek dengan button.

Demikian sedikit tutorial dari saya, semoga bermanfaat. Sampai jumpa ;-)
Selamat Belajar Flash, SEMOGA BERMANFAAT

Flash AS3 Tutorial: 3D flip effect

STEP 1: PREPARING ASSETS IN FLASH

Open Flash and create a new document in AS3. Go to File/Import/Import to stage and import two images. They should be of the same size to achieve a smooth effect. Convert them both to MovieClips (right click and then Convert to Symbol). Name first one adNumber1 and second one adNumber1. Be sure to name instances of movie clips also. You can name them with your names also but these are the names used in source files.
Flash AS3 naming Instance
Leave both images on the stage as they are, no positioning is needed since we will do that with actionscript.
[amazon_carousel widget_type="SearchAndAdd" width=600" height="200" title="" market_place="US" shuffle_products="True" show_border="False" keywords="flash tutorial, learn flash" browse_node="" search_index="Books" /]

STEP 3: POSITIONING

It is time to put our 3D flip effect to life. First you have to import Tweenlite classes that will take care of our animation.
import com.greensock.*;
import com.greensock.easing.*;
When you import images, rotation point is set at 0 (both x and y coordinates). That means our rotation wouldn’t be around the center like we would like but around left border of the image. To move rotation point to the center we will create new sprite objects and add images into them. Apply the following code:
var imageC:Sprite = new Sprite();//containers for rotation X and Y
var imageD:Sprite = new Sprite();//containers for rotation X and Y
addChild(imageC);
addChild(imageD);
imageC.addChild(adNumber1);
imageD.addChild(adNumber2);
We have defined two sprite objects, add them to stage and then inserted both images into them. Now we have to move our images along x and y axis for half of their width and height to set the rotation point to the center of the sprite:
adNumber1.x- adNumber1.width/2;
adNumber1.y- adNumber1.height/2;
adNumber2.x- adNumber2.width/2;
adNumber2.y- adNumber2.height/2;
Set inital rotation for both images to 0:
imageC.rotationX = 0;
imageD.rotationX = 0;
To set the position of your images on the stage (the exact position that you actually see) you have to apply x and y to sprite objects (not images):
imageC.x = stage.stageWidth - imageC.width;
imageC.y = stage.stageHeight -  imageC.height/2
imageD.xstage.stageWidth - imageC.width;
imageD.y = stage.stageHeight -  imageC.height/2;
Please note that this can be anything you like, in our example we set them to the center of the stage. Both sprites have to be set at the same position.

STEP 4: APPLYING THE 3D EFFECT

We are finally at the fun part. We will implement two functions that will take care of our 3D effect.
We will first define two more variables that will take care of animation time and time each image is in still position (time that image is not moving):
var animationTime:Number = 2;
var imageOnStage:Number = 3;
We will now set initial position for second image. It has to be set at 90 or -90 degrees and opacity set to 0. First function will rotate first image for 90 degrees (until it is not visible anymore) and then set it’s opacity value to 0. After first part of rotation is completed second one begins. Animation of the second image rotates it to 0 degrees (note that starting position of second one was set to -90). First function has now done it’s job. Second function now sets initial position of first image to -90 degrees and sets opacity to 0. Tweenlite animations now do exactly the same job as in first function (only images are now in different order). After first part of tween is completed we call first function again and so on. Functions will keep calling each other and our 3D flip will repeat infinitely.
function flip3D(){
     imageD.rotationX = -90;
     imageD.alpha = 0;
     TweenLite.to(imageC, animationTime, {alpha:1,delay:imageOnStage,rotationX:90,ease:Quint.easeIn, onComplete:flip3DSecond, overwrite:0})
     TweenLite.to(imageD,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0, ease:Elastic.easeOut, overwrite:0})
}

function flip3DSecond(){
     imageC.alpha = 0;
     imageC.rotationX = -90;
     TweenLite.to(imageD, animationTime, {alpha:1,delay:imageOnStage, rotationX:90,ease:Quint.easeIn, onComplete:flip3D, overwrite:0})
     TweenLite.to(imageC,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0,delay:0, ease:Elastic.easeOut,overwrite:0})
}

CONCLUSION

Our 3D flip effect is now completed but we’re far from done. If you look carefully you will notice that images are a bit blurry. That happens because of the way Flash renders 3D. In second part of our tutorial I will show you how to solve this issue. Third part of the tutorial will implement a simple 3D engine that will rotate images along all three axis (x,y,z). So stay tuned for more 3D effects! If 3D rotation is not working check if you have Flash player version 10 set as export player. Go to File/Publish Settings and select tag named Flash. Set player to version 10 if it is currently set to 9.

Flash AS3 Tutorial: 3D rotations part 3

STEP 1: INTRO

First download source files from second edition of our tutorial so you have a basic idea of what we have done so far. Currently we only have one variable that defines 3D rotations (along X axis). We will now add two more (for y and z).

STEP 2: ENGINE IMPLEMENTATION

Add following variables at the start of your code (in variables section):
var rotateX:Number = 90;
var rotateY:Number = 0;
var rotateZ:Number = 0;
Note that variables are currently set so they produce the same 3D flip as seen in previous tutorials (along X axis). Now we have to change our 3D Flip functions so they are compatible with newly added variables. We have to define starting positions for all three rotations (imageD.rotationX = -rotateX). They have to be the negative of what rotations in variables are, to produce a continuous rotation. Now we have to change TweenLite animations to function with our variables. All you have to do is set all three rotation effects to work with variables (rotationX:rotateX). RotationX is a build in function and rotateX is our variable where we set the amount of rotation. Functions should now look like this:
function flip3D(){
     imageD.rotationX = -rotateX;
     imageD.rotationY = -rotateY;
     imageD.rotationZ = -rotateZ;
     imageD.alpha = 0;
     adNumber1.z = 0;
     adNumber2.z = 0;

     TweenLite.to(imageC, animationTime, {alpha:1,delay:imageOnStage,rotationX:rotateX, rotationY:rotateY, rotationZ:rotateZ, ease:Quint.easeIn, onComplete:flip3DSecond, overwrite:0})
     TweenLite.to(imageD,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0, rotationY:0, rotationZ:0, ease:Elastic.easeOut, overwrite:0})
}

function flip3DSecond(){
     imageC.rotationX = -rotateX;
     imageC.rotationY = -rotateY;
     imageC.rotationZ = -rotateZ;
     imageC.alpha = 0;

     TweenLite.to(imageD, animationTime, {alpha:1,delay:imageOnStage, rotationX:rotateX, rotationY:rotateY, rotationZ:rotateZ,ease:Quint.easeIn, onComplete:flip3D, overwrite:0})
     TweenLite.to(imageC,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0, rotationY:0, rotationZ:0, delay:0, ease:Elastic.easeOut,overwrite:0})
}
Our implementation of simple 3D engine is finished. Check  examples below to see some different 3D animations you can make by tweaking newly added variables.
[amazon_carousel widget_type="SearchAndAdd" width=600" height="200" title="" market_place="US" shuffle_products="True" show_border="False" keywords="flash tutorial, learn flash" browse_node="" search_index="Books" /]

Rolling Newspaper Effect

STEP 1: ADDING DEPTH

Rolling newspaper animation requires implementation of depth (z axis). We have to roll our first image into the distance and when it almost disapperas it gets replaced with new image which then rolls to the front. We will add a variable called zDepth:
var zDepth:Number = 2000;
You can change value to any value but keeping it at 2000 will yield good results. We will now add zDepth to our 3DFlip functions. Please note that second image needs to be placed at 2000 depth before any animation starts. This way it waits at appropriate depth until it is triggered. Functions now look like this:
function flip3D(){
     imageD.rotationX = -rotateX;
     imageD.rotationY = -rotateY;
     imageD.rotationZ = -rotateZ;
     imageD.alpha = 0;
     adNumber1.z = 0;
     adNumber2.z = 0;
     imageD.z = zDepth;

     TweenLite.to(imageC, animationTime, {z:zDepth, alpha:1,delay:imageOnStage,rotationX:rotateX, rotationY:rotateY, rotationZ:rotateZ, ease:Linear.easeNone, onComplete:flip3DSecond, overwrite:0})
     TweenLite.to(imageD,animationTime, {z:0, alpha:1,delay:imageOnStage + animationTime, rotationX:0, rotationY:0, rotationZ:0, ease:Linear.easeNone, overwrite:0})
}

function flip3DSecond(){
     imageC.rotationX = -rotateX;
     imageC.rotationY = -rotateY;
     imageC.rotationZ = -rotateZ;
     imageC.alpha = 0;
     imageC.z = zDepth;

     TweenLite.to(imageD, animationTime, {z:zDepth,alpha:1,delay:imageOnStage, rotationX:rotateX, rotationY:rotateY, rotationZ:rotateZ,ease:Linear.easeNone, onComplete:flip3D, overwrite:0})
     TweenLite.to(imageC,animationTime, {z:0, alpha:1,delay:imageOnStage + animationTime, rotationX:0, rotationY:0, rotationZ:0, delay:0, ease:Linear.easeNone,overwrite:0})
}
When first part of our flip animation is completed we call the second one. We now set the depth of first image to 2000. Animation should now look like this:

Effect now looks a lot better but there is still something missing.
[amazon_carousel widget_type="SearchAndAdd" width=600" height="200" title="" market_place="US" shuffle_products="True" show_border="False" keywords="flash tutorial, learn flash" browse_node="" search_index="Books" /]

STEP 2: ADDING BLUR

Blur will add a final touch to our newspaper animation. It will make it look a lot more realistic. We have to set starting amount of blur for second image in first part of animation and for first image in second part of animation (just like with depth in previous step). We also have to change TweenLite to TweenMax since lite version doesn’t support blur effect. Our functions should now look like this:
function flip3D(){
     imageD.rotationX = -rotateX;
     imageD.rotationY = -rotateY;
     imageD.rotationZ = -rotateZ;
     imageD.alpha = 0;
     adNumber1.z = 0;
     adNumber2.z = 0;
     imageD.z = zDepth;

     TweenMax.to(imageD,0, {blurFilter:{blurX:blurX, blurY:blurY, quality:2}});
     TweenMax.to(imageC, animationTime, {blurFilter:{blurX:blurX, blurY:blurY, quality:2}, z:zDepth, alpha:1,delay:imageOnStage,rotationX:rotateX, rotationY:rotateY, rotationZ:rotateZ, ease:Linear.easeNone, onComplete:flip3DSecond, overwrite:0})
     TweenMax.to(imageD,animationTime, {blurFilter:{blurX:0, blurY:0, quality:2}, z:0, alpha:1,delay:imageOnStage + animationTime, rotationX:0, rotationY:0, rotationZ:0, ease:Linear.easeNone, overwrite:0})
}

function flip3DSecond(){
     imageC.rotationX = -rotateX;
     imageC.rotationY = -rotateY;
     imageC.rotationZ = -rotateZ;
     imageC.alpha = 0;
     imageC.z = zDepth;

     TweenMax.to(imageC,0, {blurFilter:{blurX:blurX, blurY:blurY, quality:2}});
     TweenMax.to(imageD, animationTime, {blurFilter:{blurX:blurX, blurY:blurY, quality:2}, z:zDepth,alpha:1,delay:imageOnStage, rotationX:rotateX, rotationY:rotateY, rotationZ:rotateZ,ease:Linear.easeNone, onComplete:flip3D, overwrite:0})
     TweenMax.to(imageC,animationTime, {blurFilter:{blurX:0, blurY:0, quality:2}, z:0, alpha:1,delay:imageOnStage + animationTime, rotationX:0, rotationY:0, rotationZ:0, delay:0, ease:Linear.easeNone,overwrite:0})
}
Our animation is now complete. You can see final result below:

CONCLUSION:

This concludes our 3D rotations series. We have covered everything from basics of Flash’s native 3D animations to 3D blur fix. We also developed a very simple 3D engine. As a final touch we added depth and blur to smooth animations a bit. Hopefully you found our series educational and entertaining and will soon develop some wacky 3D animations. Don’t forget to showcase them to us and stay tuned for more tutorials about Flash. Good luck!

Flash AS3 Tutorial: Falling Leaves

Download Flash AS3 Tutorial: Falling Leaves Source (526)

STEP 1: PREPARING ASSETS IN FLASH


Open Flash and create a new document in AS3. Go to File/Import/Import to stage and import a nice image of a forest. You can download the one we used from SXC stock photography site. Now repeat the previous step for the leaf which is included in source files (leaf.png). Convert it to MovieClip (right click and then Convert to Symbol). Name it leaf and be sure to export it for Actionscript (like in an image below). Now delete the leaf from the stage, we will add it later with Actionscript.

Export For ActionScript AS3
STEP 2: CODING IT UP

It is time to put our leaf to life. First you have to import Tweenlite classes that will take care of our animation.
import com.greensock.*;
import com.greensock.easing.*;

You also have to activate physics2D plugin. Use following code:
TweenPlugin.activate([Physics2DPlugin]);

We will now define a few variables that will hold values for size, rotation, starting position of leaves and number of leaves. Define following variables:
var size:Number;
var rotationLeaf:Number;
var xPos:Number;
var yPos:Number;
var nrLeaves:int = 40;
var leafs:Sprite = new Sprite();

Leafs is a container that will hold all our leaves that we will create on the fly. Add it to stage:
this.addChild(leafs);

Now add a new timeline that will take care of our animations. We will now create 40 leaves with a for loop:
var timeline:TimelineLite = new TimelineLite();
for (var i:int = 0; i < nrLeaves; i++) {
size = Math.random()*20 + 5;
rotationLeaf = Math.random()*360 + 450;
var l1:leaf = new leaf();
l1.width = size;
l1.height = size;
leafs.addChild(l1);
tweenDot(l1, getRandom(0, 10));
}

We will use a function Math.random() for leaf’s size and rotation to create a more realistic effect (each leaf has it’s own size and rotation speed). After that we create an instance of the leaf, apply the size and then add the leaf to our container. Last line calls the function that will put our leaves into motion. First variable defines the leaf and second one is the delay at which leaf will start it’s tween. We will use function getRandom to randomize the process (otherwise all leaves would start falling simotaniously and that is not very realistic). Function getRandom is a simple function that creates a random number between interval (in our case 0 and 10):
function getRandom(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}

[amazon_carousel widget_type="SearchAndAdd" width=600" height="200" title="" market_place="US" shuffle_products="True" show_border="False" keywords="flash" browse_node="" search_index="Books" /]
STEP 3: APPLYING THE ANIMATION

It is time to add the final part of our falling leaves animation:
function tweenDot(dot:leaf, delay:Number):void {
xPos = Math.random()*500 + 100;
yPos = Math.random()*50 - 60;
dot.x = xPos;
dot.y = yPos;
dot.alpha = 1;
timeline.insert( new TweenLite(dot, 6, { rotation:rotationLeaf, physics2D:{velocity:getRandom(10, 50), angle:getRandom(0, 180), gravity:6}, delay:delay, onComplete:removeLeafs, onCompleteParams:[dot, 0]}), timeline.currentTime);
}

First we set starting position of each leaf (we use random position for both x and y axis). And finally we animate leaves with the help of physics2D plugin . We can set velocity, angle (we used interval from 0 to 180 so leaves fall to the left and to the right) and gravity. We used random values for each leaf to increase the realistic look of the animation. You can tinker with those settings a bit to adjust the animation. Finally call the function that starts after the animation is completed to remove leaves from stage:
function removeLeafs(dot:leaf, delay:Number):void{
new TweenLite(dot, 3, {alpha:0, onComplete:tweenDot, onCompleteParams:[dot, 0]})
}

Function simply fades leaves so they slowly integrate with the background and then call the main function again to start animation all over again.

ActionScript 3.0 Function.apply

this video tutorial






How to Detect Browser and User Agent in Flash using AS3


In this, we’ll use TextFields and the help of ExternalInterface to retrieve the User Agent, through a JavaScript call, and display it in our SWF. With the User Agent stored, a simple search through the returned String will give us the Internet Browser. Here are the 5 simple steps to create a flash file which can detect Browser and User Agent.


Step 1: Set up Your Flash File

Launch the Flash and create a new Flash Document, set the stage size to 400x200px and the frame rate to 24fps.

 Step 2: Interface in flash

This is the interface we’ll be using, refer to the image above for the instance names. You can change your design as per your needs.

Step 3: Adding ActionScript

Create a new ActionScript Class (Cmd+N), save the file as Main.as and start writing below code:
package
{
    import flash.display.Sprite;
    import flash.external.ExternalInterface;
    import flash.events.MouseEvent;
    import fl.transitions.Tween;
    public class Main extends Sprite
    {
        private var userAgent:String;
        public function Main():void
        {
            more.addEventListener(MouseEvent.MOUSE_UP, showFull);
            browserTxt.text = getUserAgent();
            letterpress.text = getUserAgent();
        }
        private function getUserAgent():String
        {
            try
            {
                userAgent = ExternalInterface.call("window.navigator.userAgent.toString");
                var browser:String = "[Unknown Browser]";
                if (userAgent.indexOf("Safari") != -1)
                {
                    browser = "Safari";
                }
                if (userAgent.indexOf("Firefox") != -1)
                {
                    browser = "Firefox";
                }
                if (userAgent.indexOf("Chrome") != -1)
                {
                    browser = "Chrome";
                }
                if (userAgent.indexOf("MSIE") != -1)
                {
                    browser = "Internet Explorer";
                }
                if (userAgent.indexOf("Opera") != -1)
                {
                    browser = "Opera";
                }
            }
            catch (e:Error)
            {
                //could not access ExternalInterface in containing page
                return "[No ExternalInterface]";
            }
            return browser;
        }
        private function showFull(e:MouseEvent):void
        {
            info.fullInfo.text = userAgent;
            var tween:Tween = new Tween(info,"y",null,info.y,180,0.5,true);
        }
    }
}

An ExternalInterface call to a JavaScript function will get the User Agent string and use of the indexOf() method to search for each browser’s ID within that string; if the User Agent string contains the name of the browser you are looking for, you can assume that is the browser which the user is using. You can add a specific browser in this area. The more button will animate the info panel to the stage and reveal the full User Agent Information.
If the ExternalInterface call fails, the try-catch statement will pick this up and return a simple error message to the text box. It may fail if the SWF is being run in standalone Flash Player, or if the containing webpage prohibits its use.

Step 4: Document Class

Add the class name to the Class field in the Publish section of the Properties panel.



Step 5: Publish the File

To see the SWF in action (it can give you errors when testing in the IDE) you must open the file in the browser, you can press Shift+Cmd+F12 (File >> Publish) to Publish a HTML file and then open it, or drag the SWF from your project folder to the browser to see the file working.

I hope you liked this tutorial. Thank you for reading!