AS 3 Experiment: Bouncing balls
just a simple application….several balls of random size and color are moving around and bounce off when they hit the stage border. You need Flash Player 8.5 to view it.
http://www.box-hosting.net/~betaruce/as3/testingAS3.swf
If you cannot view it, pls kindly leave a comment here (I’m testing another new server :))
here’s the code:
package {
import flash.util.trace;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.Stage;
import flash.events.*;
import flash.geom.*;
public var sx:int;
public var sy:int;
public var numMC:int=10;
public class MC extends Sprite{
public var vx:Number=8+7*(Math.random()*2-1);
public var vy:Number=8+7*(Math.random()*2-1);
public function MC(){
graphics.beginFill(uint(255*Math.random())< <16|uint(255*Math.random())<<8|uint(255*Math.random()));
graphics.lineStyle(1,0);
graphics.drawCircle(0,0,10+40*Math.random());
x=Math.random()*sx;
y=Math.random()*sy;
addEventListener(EventType.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(e:Event){
if(x<=width/2){x=width/2; vx*=-1;}
if(x>=sx-width/2) {x=sx-width/2; vx*=-1;}
if(y< =width/2) {y=width/2; vy*=-1;}
if(y>=sy-width/2) {y=sy-width/2; vy*=-1;}
x+=vx;
y+=vy;
}
}
public class testingAS3 extends Sprite {
public function testingAS3() {
stage.scaleMode = StageScaleMode.SHOW_ALL;
stage.align=’TOP_LEFT’;
sx=stage.stageWidth;
sy=stage.stageHeight;
this.graphics.lineStyle(0,0);
this.graphics.beginFill(0×444444,100);
this.graphics.drawRect(0,0,sx,sy);
this.graphics.endFill();
for(var i:int=0;i
var temp:Sprite=new MC();
stage.addChild(temp);
}
}
}
}
One interesting finding is that for the following part:
graphics.drawCircle(0,0,10+40*Math.random());
x=Math.random()*sx;
y=Math.random()*sy;
the x and y parameters of drawCircle must be set to zero in order for the code to work properly as it is now, or else it seems cannot detect the correct stage border. Therefore I need to random the the ball position in the next 2 lines.
not sure why is that so, hope I will know more later.
[...] from JPEG (source code and example) Msn Messenger in Flex 2.0…Almost!?!?!? Security??? AS 3 Experiment: Bouncing balls Betaruce (source and example) AS 3 Experiment: Animated Plas [...]
Pingback by Franto.com Flash blog » Collected links to ActionScript 3.0 examples — October 26, 2005 @ 4:09 pmHere’s the one to beat: 250.000 REAL bouncing balls
http://www.bravia-advert.com/gallery/gallery02.html
J
Comment by Jensa — October 26, 2005 @ 6:47 pmpushing Flash to the limit
Comment by betaruce — October 26, 2005 @ 7:24 pmCant see your flash movies dude.
Comment by Bob — November 4, 2005 @ 10:26 pmdo you have Flash Player 8.5? or is it my server problem?
Comment by betaruce — November 4, 2005 @ 10:46 pmI can’t view it! I just got the flash player 15 mins. ago!
Comment by you — January 2, 2006 @ 7:47 amI’m not sure I got the .5 version though. Leave a Link!
http://labs.macromedia.com/technologies/flashplayer8_5/
pls leave a comment if you still cannot see it
Comment by betaruce — January 2, 2006 @ 8:47 amRealmente tengo gusto de este Web site. Usted todo ha hecho un buen trabajo.
Comment by Danald — June 13, 2006 @ 7:35 amThat is the nicest ,coolest
Comment by lenny — August 25, 2006 @ 6:46 pmthing I’ve heard for a long time. I really appreciate your work. I’ll share it
with my friends.
http://www.box-hosting.net/~betaruce/as3/testingAS3.swf
Comment by Mak 000001 — January 29, 2007 @ 4:24 pmnot going anywhere.
That is the nicest ,coolest thing. Thanks.
Comment by ball — March 2, 2007 @ 11:52 amyes it is very coolest thing for flesh player but their
Comment by jack — March 27, 2007 @ 3:08 pmis ans other player which was introduce in 2006 was
(youtube) which is getting success day by day and i
think it is great part of internet.
[...] Experimentos de AS3: Bola con Bouncing Betaruce [...]
Pingback by DeCabeza.net » Colección de link útiles sobre ActionScript 3 - desarrollo web, tutoriales, video tutoriales, videotutoriales, flash, photoshop, php, mysql, dreamweaver — June 27, 2008 @ 10:28 pmwhy i cann’t see the flash,also after check the code.
Comment by pobobo — July 4, 2008 @ 11:07 pmvery cool,I like it,thanks
Comment by thepowerlevel — July 4, 2008 @ 11:12 pmCoolest thing. Thanks.
Comment by 紋身 — October 21, 2008 @ 11:05 amthanks
Comment by rug — November 26, 2008 @ 5:28 pmhttp://nathan.toys-kingdom.com/
Comment by sdfsdfds — May 11, 2009 @ 3:05 pm[...] Experimentos de AS3: Bola con Bouncing Betaruce [...]
Pingback by Colección de link útiles sobre ActionScript 3 « DeCabeza.net — August 11, 2009 @ 10:56 amvery nice
Comment by metin2 yang — February 23, 2010 @ 11:52 amExperimentos de AS3: Bola con Bouncing Betaruce
Comment by 赛尔号 — March 4, 2010 @ 2:36 pmjust a simple application….several balls of random size and color are moving around and bounce off when they hit the stage border. You need Flash Player 8.5 to view it
Comment by 网页游戏 — March 16, 2010 @ 11:41 amwedding invitations wedding invitations
Comment by coco — May 14, 2010 @ 3:44 pmMany players said that 2moons dil
Comment by 2moons dil — May 21, 2010 @ 2:30 pmCoolest thing. Thanks.
Comment by 成都SEO — June 18, 2010 @ 5:03 pmI pride to be citizen of the world, so I am also hoping that the Hindu’s class system of “Royal(lords) and peasant (commoner)will change”, so the education level will improve together with the knowledge, virtues and economy.
Comment by Aşık Etme Büyüsü — August 25, 2010 @ 5:10 pmChina had forgotten the past history with Japan. The former Premiere Mr. Deng Xiao Ping , when asked by the Japanese premiere about twenty five years ago.” about the return of the northern island back to China.” Mr. Dan replied:” Slow down, we wouldn’t know how the politics of the world is going to be fifty years from now.” Most recently, Mr. Hu said:” We hope Japan will involve in greater part of the affair of the world. We are happy to see the peaceful path Japan takes since the Thank you for sharing