Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- How to blend adsense inside your post?
- Formatting my post
- Notepad++ - Add C++ compiler
- Install PHPMailer 5.2.4 and use smtp gmail
- Set up a child account and set screen time limit in Windows 8
- Wayback Machine - see archived versions of web pages across time
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHP ibm_db2 extension in Linux (redHat)
- PHP: add a download as pdf file button in report page
Friday, May 11, 2012
Design a bouncing ball flash
To design a bouncing ball in flash using ActionScript 3.0,
1) Start Flash CS5, click new-> actionscript 3.0, create a rectangle at Center using Rectangle Tool, convert it to MovieClip with name mb and the instance name: mybox
2) Create a ball and convert it to a MovieClip with name mc, in linkage select check box: Export to ActionScriot and Export to frame 1, name class as mc.
3) Press F9, input following ActionScript (require mybox at center)
var mymc:mc=new mc();
mybox.addChild(mymc);
var ball_radius=20;
var maxx:int=mybox.width/2-ball_radius;
var maxy:int=mybox.height/2-ball_radius;
var xflay:Boolean,yflay:Boolean;
var p:uint=1;
setInterval(peng,10);
function peng(){
//trace(mymc.y);
if(mymc.x>maxx-10 || mymc.x<-maxx) xflay=!xflay;
if(mymc.y>maxy || mymc.y<-maxy) yflay=!yflay;
if(xflay) mymc.x-=p;
else mymc.x+=p;
if(yflay) mymc.y-=p;
else mymc.y+=p;
}
4) Export flash, below is the result:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment