Groups | Blog | Home
all groups > flash actionscript > april 2004 >

flash actionscript : tweening or actionscript: performance issue


benari004
4/20/2004 9:48:41 PM
I've hunted around for discussion on the issue of performace improvement using
actionscript instead of tweens. Nothing. Please respond with advice or a
"definately actionscript and here's why"--or perhaps a pointer to an already
existing thread.

I'm building a series of applications that connect photographs with text;
these fade in and out, and because of the many tweens, performance suffers.
What I've read is that actionscripting eliminates the use of keyframes and all
that's carried between them, and so improves performance. (Again, I'm new to
all this, so discussion is quite helpful).

I've begun rebuilding in actionscript, which provides way more elegance and
functionality; but I'm not noticing much improved performance.

One example: fading a movieclip using

onEventClip(enterFrame){

if(this._currentframe == 1){
this._alpha = 0;
}else{
if(this._currentframe > 1 && this._currentframe < 24){
this._alpha +=2;
}
}
}

I get the same "stuttered" fade I get with the many tweens through out this
particular timeline. Of course image size, processor and my coding are all at
play (if you have suggestions about how to improve the above code, please let
fly). But what's your view on performance improvements through [i]as[/i]?

Thanks,

--benari
Jack.
4/21/2004 11:19:53 AM
[quoted text, click to view]

fading bitmaps is cpu intensive, far better (when possible)
to place a background colored movieclip over the bitmap
and fade the movieclip, something like -

PATH = "images/";
arr=["image001","image002","image003","image004",
"image005","image006","image007"];
arr2=["A text","B text","C text","D text","E text","F text","G text"];

coord=[800,530,0,0];
waitTime = 1500; // stay at full alpha - msecs
upSpeed = 1;
downSpeed = 1;
/**************/
createEmptyMovieClip("cover",124);
with(cover){
lineStyle(1,0x000000,10); beginFill(0x000000);
lineTo(coord[0],0); lineTo(coord[0],coord[1]);
lineTo(0,coord[1]); lineTo(0,0);
_x=coord[2]; _y=coord[3]; endFill();
}
/**************/
function fader(dir){
if(dir){ loadJPG(pic); pic++;
cover.onEnterframe = function(){ coverDn();
pic > arr.length ? _level0.gotoAndStop("gam") : null; };
}else
cover.onEnterframe = function(){ coverUp();};
};
/**************/
function coverUp(){ trace("cover up");
cover._alpha += upSpeed;
if(cover._alpha > 100){
cover._alpha = 100; timer = 0; fader(1);}
};
/**************/
function coverDn(){ trace("cover down");
cover._alpha -= downSpeed;
if(cover._alpha < 0){ cover._alpha = 0; hold(waitTime);}
if(timer) fader(0);
};
/**************/
function hold(mSecs){ trace("hold");
if(!pause){
pause = getTimer() + mSecs;
} else if (getTimer() > pause){
pause = 0; timer = 1;
}
};
/**************/
function loadJPG(pic){
txt.text = arr2[pic];
createEmptyMovieClip("loadr",123);
loadr.loadMovie(PATH+arr[pic]+".jpg");
this.onEnterFrame = function(){
if(loadr._width > 0){
loadr._x = cover._x+cover._width/2-loadr._width/2;
loadr._y = cover._y+cover._height/2-loadr._height/2;
delete this.onEnterFrame;
}
};
};

pic=0; fader(1);

hth,
benari004
4/21/2004 12:07:42 PM
this is great advice. I appreciate the code and of course you'll be hearing
back from me about all my errors in implementing it, which I'll start on
tonight.

Thanks for the advice and the code.

--benari
AddThis Social Bookmark Button