Getting used to AS3 and working sans library

Hello,

For an upcoming project I’m going to be using a fast, lightweight physics engine I developed recently in AS2.

I’ve been putting off learning AS3 for too long, so I thought now is as good a time as any to get out of my comfort zone and start using AS3.

I’m porting the engine to AS3. Porting all the classes is going to be very easy, because they are setup to be controlled from a single, external onEnterFrame event, they don’t extend MovieClips, they don’t have any listeners themselves etc. All I need to do is change some of the syntax.

Now what I’d like some advice on is something more simple, just setting things up from the document class.

In AS2 here is some constructing code for something I used the physics engine for recently.

[AS]
var NUM_PARTICLES:Number = 20;
var LE_GRID = new GRID(WORLD.BG);
var BALLS = new BALL_PHYSICS();
var CAM = new TRACKING_CAM_03():
BALLS.world = WORLD;
BALLS.ID = “BALLS”;
LE_GRID.balls = BALLS;
//
for (var i = 0; i<NUM_PARTICLES; i++) {
var new_particle = new BALL_PARTICLE();
new_particle.RADIUS = 50+random(50);
new_particle.WEIGHT = new_particle.RADIUS*0.02;
var my_ball = WORLD.SPRITES.attachMovie(“m_flower_01”, “m_flower”+i, i);
new_particle.MC = my_ball;
BALLS.ADD_PARTICLE(new_particle);
}
//
WORLD.onEnterFrame = function() {
BALLS.VERLET();
BALLS.RENDER_SPRITES();
BALLS.GRAB();
BALLS.COLLISION();
CAM.UPDATE();
};
[/AS]

my_ball is a library MC that contains a bitmap. That gets linked to a particle, which is passed into my BALL_PHYSICS class, which controls the movement of the particles.

What would be the best way to go about this in Flex?

I could load in the PNG externally, and when it’s loaded, call the for loop that loads the particles. Or I could just use [Embed(source=“m_flower_01.png”)] so the bitmap essentially becomes a library item.

But what would be the most efficient way of attaching the bitmap to 20 sprites, and then passing those into my physics class?

In AS2 if I loaded the PNG in externally, I would draw it’s parent MC to a bitmapData object, then attach that BMD to 20 empty MC’s.

That’s because in AS2 you couldn’t load a bitmap in as a BMD.

Has that changed in AS3? Can I load a bitmap in as a BitmapData or even Bitmap object?

Excuse me if it’s a little long winded :wink: In a nutshell, what would be the most efficient way in Flex of loading in a PNG, attaching it to 20 blank sprites, which then get linked to a particle in a physics engine :smiley:

Cheers,
Joe