Hey,
I have a poblem. I have this code that scales my clips and loads a movieclip in to the holder mc. What my problem is when I go to click on a clip before it scales down it does not resize to the right size i want. If you go to http://www.indulge-in-grahams.com/site/
then click on one of the bars then quickly click on another, the previous clip does not resize properly and evetually pushes all the other clips off stage. Below is the complete code I am using.
stop();
loadingBar._visible = false;
infotxt._visible = false;
// Initial variables
var numClips = 10;
// number of clips
var speed = 10;
// velocvity of animation.
var speedRatio = speed/10;
// speed ration for elasticity
var friction = 0.7;
// friction on animation.
var itemArray = new Array();
// holds all clips
var clickedItem = null;
// clicked on
var selectedItem = null;
// currently selected
var growingItem = null;
// currently growing
var reducingItem = null;
// currently reducing
_global.scaleCountdown = 0;
// countdown to scale animation
_global.scaleDelay = 1;
// number of secs to countdown
//Initiate Animation
this.initAnim = function() {
// setup the clips in array
for (var i = 0; i<=numClips; i++) {
// get reference to clip
var clip = this["clip_"+i];
// define initial properties
clip.w = clip.bg_mc._width;
// initial width
clip.h = clip._height;
// initial height
clip.tw = 330;
// target width
clip.th = clip.h;
// target height
clip.dw = 0;
// distance to target width
clip.dh = 0;
// distance to target height
// add to array
itemArray* = clip;
// Set click
clip.onRelease = setClick;
clip.onPress = startScaling;
// Start stop scaling
//clip.onRollOver = startScaling;
//clip.onRollOut = endScaling;
}
// set first item to grow
clickedItem = selectedItem=itemArray[0];
// Set render
this.onEnterFrame = render;
};
// render animation
this.render = function() {
friction = slide/100;
// if scale countdown reaches 0 and user rolls over a new item start scale
if (scaleCountdown-- == 0 && growingItem != selectedItem) {
// set old growing item to new reducing item
reducingItem = growingItem;
// set growing item as selected item
growingItem = selectedItem;
}
if (scaleCountdown == -scaleDelay*51) {
if (selectedItem == itemArray[0]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.bighold._width<10) {
bighold.loadMovie("bigbun.swf");
bighold._x = clip_0._x;
bighold._y = clip_0._y;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.bighold.getBytesLoaded()/1024;
kBytesTotal = this._parent.bighold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
loadingBar._visible = false;
infotxt._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("0 is off");
}
}
if (selectedItem == itemArray[1]) {
loadingBar._visible = true;
infotxt._visible = true;
if (_root.eathold._width<10) {
eathold.loadMovie("eatme.swf");
eathold._x = clip_1._x-1.3;
eathold._y = clip_1._y-.5;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.eathold.getBytesLoaded()/1024;
kBytesTotal = this._parent.eathold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
loadingBar._visible = false;
infotxt._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("1 is off");
}
}
if (selectedItem == itemArray[2]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.nyhold._width<10) {
nyhold.loadMovie("nybagel.swf");
nyhold._x = clip_2._x;
nyhold._y = clip_2._y;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.nyhold.getBytesLoaded()/1024;
kBytesTotal = this._parent.nyhold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("2 is off");
}
}
if (selectedItem == itemArray[3]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.grhold._width<10) {
grhold.loadMovie("grahams_hold.swf");
grhold._x = clip_3._x-1;
grhold._y = clip_3._y-1;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.grhold.getBytesLoaded()/1024;
kBytesTotal = this._parent.grhold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("3 is off");
}
}
if (selectedItem == itemArray[4]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.prhold._width<10) {
prhold.loadMovie("profile.swf");
prhold._x = clip_4._x-1;
prhold._y = clip_4._y-1;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.prhold.getBytesLoaded()/1024;
kBytesTotal = this._parent.prhold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("4 is off");
}
}
if (selectedItem == itemArray[5]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.rechold._width<10) {
rechold.loadMovie("recipies.swf");
rechold._x = clip_5._x-1;
rechold._y = clip_5._y;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.rechold.getBytesLoaded()/1024;
kBytesTotal = this._parent.rechold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("5 is off");
}
}
if (selectedItem == itemArray[6]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.newshold._width<10) {
newshold.loadMovie("news.swf");
newshold._x = clip_6._x-1.3;
newshold._y = clip_6._y-1;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.newshold.getBytesLoaded()/1024;
kBytesTotal = this._parent.newshold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("6 is off");
}
}
if (selectedItem == itemArray[7]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.linkshold._width<10) {
linkshold.loadMovie("gallery.swf");
linkshold._x = clip_7._x;
linkshold._y = clip_7._y;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.linkshold.getBytesLoaded()/1024;
kBytesTotal = this._parent.linkshold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt.text = "";
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("7 is off");
}
}
if (selectedItem == itemArray[8]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.contacthold._width<10) {
contacthold.loadMovie("contact.swf");
contacthold._x = clip_8._x-1.3;
contacthold._y = clip_8._y;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.contacthold.getBytesLoaded()/1024;
kBytesTotal = this._parent.contacthold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("8 is off");
}
}
if (selectedItem == itemArray[9]) {
infotxt._visible = true;
loadingBar._visible = true;
if (_root.playhold._width<10) {
playhold.loadMovie("play.swf");
playhold._x = clip_9._x;
playhold._y = clip_9._y;
loadingBar._yscale = 1;
loadingBar.onEnterFrame = function() {
kBytesLoaded = this._parent.playhold.getBytesLoaded()/1024;
kBytesTotal = this._parent.playhold.getBytesTotal()/1024;
percentage = Math.round(kBytesLoaded/kBytesTotal*100);
this._yscale = percentage;
infotxt.text = "please wait...";
if (percentage == 99) {
infotxt._visible = false;
loadingBar._visible = false;
delete this.onEnterFrame;
}
};
} else {
trace("9 is off");
}
}
}
// unload all movies that are not active
if (selectedItem == itemArray[0]) {
null;
} else {
bighold.unloadMovie("bigbun.swf");
}
if (selectedItem == itemArray[1]) {
null;
} else {
eathold.unloadMovie("eatme.swf");
}
if (selectedItem == itemArray[2]) {
null;
} else {
nyhold.unloadMovie("nybagel.swf");
}
if (selectedItem == itemArray[3]) {
null;
} else {
grhold.unloadMovie("grahams_hold.swf");
}
if (selectedItem == itemArray[4]) {
null;
} else {
prhold.unloadMovie("profile.swf");
}
if (selectedItem == itemArray[5]) {
null;
} else {
rechold.unloadMovie("recipies.swf");
}
if (selectedItem == itemArray[6]) {
null;
} else {
newshold.unloadMovie("news.swf");
}
if (selectedItem == itemArray[7]) {
null;
} else {
linkshold.unloadMovie("gallery.swf");
}
if (selectedItem == itemArray[8]) {
null;
} else {
contacthold.unloadMovie("contact.swf");
}
if (selectedItem == itemArray[9]) {
null;
} else {
playhold.unloadMovie("play.swf");
}
// assign growing item properties
var clip = growingItem;
// Calculate distance growing Item has to travel
clip.dw = (clip.tw-clip.bg_mc._width)/speed*speedRatio+clip.dw*friction;
clip.dh = (clip.th-clip._height)/speed*speedRatio+clip.dh*friction;
// resize selected clip
clip.bg_mc._width += clip.dw;
clip._height += clip.dh;
// assign growing item properties
var clip = reducingItem;
// Calculate distance reducing Item has to travel
clip.dw = (clip.w-clip.bg_mc._width)/speed*speedRatio+clip.dw*friction;
clip.dh = (clip.h-clip._height)/speed*speedRatio+clip.dh*friction;
// resize old clip
clip.bg_mc._width += clip.dw;
clip._height += clip.dh;
// make next clip position reflect previous clips
for (var i = 0; i<=numClips; i++) {
// make next clip position reflect previous clips
itemArray[i+1]._x = itemArray*._x+itemArray*._width+3;
// make growing orange
(itemArray* == growingItem) ? itemArray*.gotoAndStop(2) : itemArray*.gotoAndStop(1);
}
};
this.setClick = function() {
scaleCountdown = scaleDelay;
// make this item teh clicked Item
clickedItem = this;
};
this.startScaling = function() {
// reset scale countdown
scaleCountdown = scaleDelay;
// make this item the selected item (start scale)
selectedItem = this;
};
this.endScaling = function() {
// reset scale countdown
scaleCountdown = scaleDelay;
// make previousely clicked item the selected item (start scale)
selectedItem = clickedItem;
};
// Initiate animation
initAnim();
Any help would be greatly appreciated and I hope somebody is willing to help.
regards,
Dee