Groups | Blog | Home
all groups > flash actionscript > january 2006 >

flash actionscript : need to animate through action script


batgirl_Sa
1/1/2006 10:20:42 AM
Hi... i am hoping someone can help me...

i want to do animation but using action script rather than on the time
line... firt of all i want to have 5 pictures on my stage and when i click on a
picture i want the picture to get larger and move tothe middle and and the
other pictures to fade out a bit and get smaller.... now i can do this on the
time line with tweening but i want to know if i can do this using action
script.....

HELP!!!

thanks
NSurveyor
1/1/2006 3:57:52 PM
Convert each image to a MovieClip and give each one an Instance Name. Place
the attached code to the current frame. Make sure to add your clips to the
clips array on the first line:

clips = [instance1, instance2, instance3, instance4, instance5];
//For each clip:
for (var c = 0; c<clips.length; c++) {
//current clip
cClip = clips[c];
//set initial alpha to 0
cClip._alpha = 20;
//rememeber initial position
cClip.ox = cClip._x;
cClip.oy = cClip._y;
//Create an array of the other clips
cClip.otherClips = clips.slice();
cClip.otherClips.splice(c, 1);
//When this clip is pressed
cClip.onPress = function() {
//Toggle it's "active" property
this.active = !this.active;
if (this.active) {
//If active, ease to 100 alpha, and center coordinates
this.tweenTo(100, (Stage.width-this._width)/2,
(Stage.height-this._height)/2);
} else {
//If not, ease to 20 (initial) alpha, and initial coordinates
this.tweenTo(20, this.ox, this.oy);
}
//For each of the other clips:
for (var o = 0; o<this.otherClips.length; o++) {
//Current 'other' clip
var oClip = this.otherClips[o];
//Set "active" property to false
oClip.active = false;
//Ease to 20 (initial) alpha, and initial coordinates
oClip.tweenTo(20, oClip.ox, oClip.oy);
}
};
}
MovieClip.prototype.tweenTo = function(targetA, targetX, targetY) {
//Loop:
this.onEnterFrame = function() {
//Ease to target properties
this._alpha += (targetA-this._alpha)/10;
this._x += (targetX-this._x)/10;
this._y += (targetY-this._y)/10;
//If finished, set to exact settings and stop onEnterFrame
var cond1 = Math.abs(targetA-this._alpha)<1;
var cond2 = Math.abs(targetX-this._x)<1;
var cond3 = Math.abs(targetY-this._y)<1;
if (cond1 && cond2 && cond3) {
this._alpha = targetA
this._x = targetX;
this._y = targetY;
delete this.onEnterFrame;
}
};
};
AddThis Social Bookmark Button