Hey all, I can't say that I'm new to AS3, I've been working with it alot, and doing loads of stuff with it, and it's great so far, but one thing I have always had trouble with, is the amount of code I use. I'm pretty sure there is a cleaner, simpler way of doing things, but I guess I'll have to learn a bit at a time.
So I'll start here.
This is part of the code I'm using for a little experiment that I've put together. It works fine, just needs cleaning.
There is a single movieclip on the stage, and to start, it is duplicated to 4 childs. These childs have 4 seperate rotations (0,90,180,270) and then they are duplicated lots of times on those settings, using a timer.
I was sure that I saw a simpler way of doing this somewhere, but I really can't remember where I saw it, and I haven't the foggiest what I need to look for, simply because I don't know what it's called.
I'll also add the fla file, just in case.
Any help would be awesome! Thanks guys!
ATT: Light_Rotation.fla
Code:
function createTrailBall(e:Event):void {
// Create Child1 and add info
var trailBall1:Orb=new Orb();
trailBall1.x = trailPosition;
trailBall1.y = trailPosition;
trailBall1.rotation = 0;
// Create Child2 and add info
var trailBall2:Orb=new Orb();
trailBall2.x = trailPosition;
trailBall2.y = trailPosition;
trailBall2.rotation = 90;
// Create Child3 and add info
var trailBall3:Orb=new Orb();
trailBall3.x = trailPosition;
trailBall3.y = trailPosition;
trailBall3.rotation = 180;
// Create Child4 and add info
var trailBall4:Orb=new Orb();
trailBall4.x = trailPosition;
trailBall4.y = trailPosition;
trailBall4.rotation = 270;
[COLOR="DimGray"]
//Start the next function for rotation and alpha changes
trailBall1.addEventListener(Event.ENTER_FRAME,animateTrailBall);
trailBall2.addEventListener(Event.ENTER_FRAME,animateTrailBall);
trailBall3.addEventListener(Event.ENTER_FRAME,animateTrailBall);
trailBall4.addEventListener(Event.ENTER_FRAME,animateTrailBall);
//Add Childs to stage
addChildAt(trailBall1,0);
addChildAt(trailBall2,0);
addChildAt(trailBall3,0);
addChildAt(trailBall4,0);
}
// Function for changeing Childs on stage
function animateTrailBall(e:Event):void {
e.target.rotation += rotationSpeed;
e.target.alpha -= 0.01;
if (e.target.alpha <= 0) {
e.target.removeEventListener(Event.ENTER_FRAME,animateTrailBall);
removeChild((MovieClip)(e.target));
}
}
function createTrailBall(e:Event):void {
var trailBall:Orb;
for(var i:int=0; i < 4; i++){
// Create Child and add info
trailBall:Orb=new Orb();
trailBall.x = trailPosition;
trailBall.y = trailPosition;
trailBall.rotation = i*90;
//Start the next function for rotation and alpha changes
trailBall.addEventListener(Event.ENTER_FRAME,animateTrailBall);
//Add Childs to stage
addChildAt(trailBall,0);
}
}
// Function for changing children on stage
function animateTrailBall(e:Event):void {
e.target.rotation += rotationSpeed;
e.target.alpha -= 0.01;
if (e.target.alpha <= 0) {
e.target.removeEventListener(Event.ENTER_FRAME,animateTrailBall);
removeChild((MovieClip)(e.target));
}
}
for loops are a basic looping mechanism in almost all programming languages (including as1 and as2). It simply initializes with one statement, loops over some block of code while a second statement is true, and changes something between loops with a third statement. Usually it's used as above to go from one number to another hitting all of them in between.
Honestly, that's a weird question from someone who
can't say that I'm new to AS3, I've been working with it alot, and doing loads of stuff with it