Tuesday, January 1, 2013

Actionscript 3.0 demo - create a flying bird in flash



Below is the example to create a flying bird in Flash CS6 using ActionScript 3.0.
1) Open Adobe Flash CS6 File->New->ActionScript 3.0
2) Stage width 550, height 400, File-> import to stage with background image (550*400) in layer bg (rename layer1 as bg)
3) Create layer 1. Using  oval tool and brush tool to create   a bird without wings.
convert the whole bird to Movie Clip "bird" registration point at center. check the box "export to actionscript".
4)double click the bird, convert it to  movieclip with name birdbody
5) In timeline 10, insert keyframe for wing and body,create motion tween between timeline 1 and 10
6) Go back to scene , create layer action. Press F9 to input the following actionscript

addEventListener (Event.ENTER_FRAME,birdMV);
function birdMV (event:Event):void {
    var reduce:Number=Math.random()*100;
    if(reduce>0 &&reduce<5){
    var scale:Number=Math.random()*.3;
    var _sf:bird=new bird();
    _sf.y=Math.random()*400;
    _sf.scaleX=scale;
    _sf.scaleY=scale;
    var speed:Number=Math.random()*10;
    var RA:Array=new Array(-1,1);
    var lf:int=RA[Math.round(Math.random())];
    stage.addChild (_sf);
    _sf.addEventListener (Event.ENTER_FRAME,birdflying);
    }
    function birdflying (event:Event):void {  
        _sf.x+=speed;
        if(_sf.x>580) _sf.x = 0;
        _sf.y+=(Math.random()*3)*lf;
    }

6) Export or test flash, done.

flash output




video:

No comments:

Post a Comment