This is a blog about Flash & AS by betaruce :-)



Calendar

August 2007
M T W T F S S
« Jul    
  1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31  

October 25, 2005

AS 3 Experiment: Bouncing balls

Filed under: My Flash Programs — betaruce @ 8:46 pm

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.

• • •

12 Comments »

  1. […] 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 pm
  2. Here’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 pm
  3. pushing Flash to the limit

    Comment by betaruce — October 26, 2005 @ 7:24 pm
  4. Cant see your flash movies dude.

    Comment by Bob — November 4, 2005 @ 10:26 pm
  5. do you have Flash Player 8.5? or is it my server problem?

    Comment by betaruce — November 4, 2005 @ 10:46 pm
  6. I can’t view it! I just got the flash player 15 mins. ago!
    I’m not sure I got the .5 version though. Leave a Link!

    Comment by you — January 2, 2006 @ 7:47 am
  7. 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 am
  8. Realmente tengo gusto de este Web site. Usted todo ha hecho un buen trabajo.

    Comment by Danald — June 13, 2006 @ 7:35 am
  9. That is the nicest ,coolest
    thing I’ve heard for a long time. I really appreciate your work. I’ll share it
    with my friends.

    Comment by lenny — August 25, 2006 @ 6:46 pm
  10. http://www.box-hosting.net/~betaruce/as3/testingAS3.swf
    not going anywhere.

    Comment by Mak 000001 — January 29, 2007 @ 4:24 pm
  11. That is the nicest ,coolest thing. Thanks.

    Comment by ball — March 2, 2007 @ 11:52 am
  12. yes it is very coolest thing for flesh player but their
    is 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.

    Comment by jack — March 27, 2007 @ 3:08 pm

Comments RSS • TrackBack URI

Leave a comment

Powered by: WordPress • Template by: Priss

cheap phentermine phentermine site phentermine effects online phentermine phentermine prescription buy phentermine online phentermine alternatives phentermine deit pill cheap generic phentermine order phentermine online Clenbuterol Phentermine online pharmacy phentermine buy phentermine weight loss pill Cialis Comparison Viagra Cheap Viagra Online Prescription generic viagra sale viagra online viagra viagra pill discount sale viagra Generico Impotencia Viagra viagra sildenafil citrate Xanax Online xanax order xanax valium versus xanax levitra order levitra levitra Online buy levitra cialis viagra levitra