Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Actionscript problem 1

Status
Not open for further replies.

paulw1982

MIS
Aug 6, 2003
41
AU
Hello

What is the best way to use actionscript to have a line slowly draw down the screen when a frame loads.

i have tried this:

x=100
do {
lineStyle(5,0xffffff,100);
moveTo(250,100);
lineTo(250,x);
x+=1
} while (x<200);

but its so quich you cant even notice it drawing.

Please could somebody tell me why its so quick when I do it my way and also let me know the best way to do it.


Thanks
 
This script is way above my level, but... could there be an expression for time that's missing?
 
I dont think so. I've looked but cant find anything.

Thanks anyway.
 
Try this...
Code:
createEmptyMovieClip(&quot;line1&quot;,100);
sp = 10; // increment (speed)
w = 100; // width
h = 100; // height
this.onEnterFrame = function(){
pos1 < w ? pos1 += sp : draw2 = 1;
if(draw2) pos2 < h ? pos2 += sp : draw3 = 1;
if(draw3){ apos3 < w ? apos3 += sp : draw4 = 1;
pos3 = w - apos3;}
if(draw4){ apos4 < h  ? apos4 += sp : delete this.onEnterFrame;
pos4 = h - apos4; }
        
//trace(pos1+&quot; -- &quot;+pos2+&quot; -- &quot;+pos3+&quot; -- &quot;+pos4);
        
with(line1){
line1._x = 100;
line1._y = 10;
clear();
lineStyle( 3, 0xff0000, 100 );
lineTo(pos1,0);        //(100,0);
if(draw2) lineTo(pos1,pos2);    //(100,100);
if(draw3) lineTo(pos3,pos2);   //(0,100);
if(draw4) lineTo(0,pos4);     //(0,0);
}
};

Regards,

cubalibre2.gif
 
It's quick because the entire loop executes on one frame. To stretch the effect out over time it needs to be frame or time based.

You can do it based on time by using setInterval like this:

drawingInterval=setInterval(drawingFunction,100)

...which would call a drawing function every 100 milliseconds.

Based on frames you could do something like:

this.onEnterFrame=drawingFunction;

Taking the code you have already and putting it on the main timeline in a function would look like this:

x = 100;
drawingFunction = function () {
trace(&quot;hitting&quot;);
lineStyle(5, 0xffffff, 100);
moveTo(250, 100);
lineTo(250, x);
if (x<200) {
x++;
} else {
// this.onEnterFrame = null;
clearInterval(drawingInterval);
}
};
//this.onEnterFrame = drawingFunction;
drawingInterval = setInterval(drawingFunction, 100);
//
stop();

...if you uncomment the 'enterFrame' stuff and comment out the 'interval' stuff you can compare the two methods
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top