In one the pages in my site I have three seperate areas that have scrollable text and pictures. The code I am using for the scrolling uses huge amounts of CPU power. It bogs down the entire flash page. Does anyone see how I could perhaps optimzie this code to save some cpu consumtion? (btw- all text is static text)
Here’s the code:
import flash.filters.BlurFilter;
blur = new BlurFilter(0, 10, 1);
scrolling = function (easing)
{
var moveSpeed:Number = 5;
var easingSpeed:Number = 4;
var scrollHeight:Number = scrollbg._height;
var scrollable:Number = contentMain._height-maskedView._height;
var initContentPos:Number = contentMain._y;
// the drag positions that are possible for the dragger
var left:Number = scrollbg._x;
var top:Number = scrollbg._y;
var right:Number = scrollbg._x;
var bottom:Number = scrollbg._height-dragger._height+scrollbg._y;
if (scrollable<0)
{
dragger._visible = false;
btnUp.enabled = false;
btnUp._alpha = 50;
btnDown._alpha = 50;
scrollbg._alpha = 50;
btnDown.enabled = false;
return;
}
function updateContentPos()
{
var percent_scrolled:Number = (dragger._y-top)/(scrollHeight-dragger._height);
contentMain.newY = Math.round(initContentPos-(percent_scrolled*scrollable));
}
contentMain.onEnterFrame = function()
{
if (!easing || easing == undefined)
{
this._y = this.newY;
}
else
{
this._y += (this.newY-this._y)/easingSpeed;
mainMovement = this.newY-this._y;
blur.blurY = Math.floor(Math.abs(mainMovement));
contentMain.filters = [blur];
}
};
dragger.onPress = function()
{
startDrag(this, false, left, top, right, bottom);
this.onMouseMove = function()
{
updateContentPos();
};
};
dragger.onMouseUp = function()
{
stopDrag();
delete this.onMouseMove;
};
btnUp.onPress = function()
{
this.onEnterFrame = function()
{
dragger._y = Math.max(top, dragger._y-moveSpeed);
updateContentPos();
};
};
btnUp.onDragOut = function()
{
delete this.onEnterFrame;
};
btnUp.onRelease = function()
{
delete this.onEnterFrame;
};
btnDown.onPress = function()
{
this.onEnterFrame = function()
{
dragger._y = Math.min(bottom, dragger._y+moveSpeed);
updateContentPos();
};
};
btnDown.onRelease = function()
{
delete this.onEnterFrame;
};
btnDown.onDragOut = function()
{
delete this.onEnterFrame;
};
updateContentPos();
};
scrolling(true);
Any help would be much appreciated