-
Writing code in AS file : problem calling function
Hi,
in a .as file, I have written two different functions, that I call in my main movie. The first one always works, and the second one never...
Any reason? Do tell me if you need the code.
Thanks,
Manojo
-
Yes, we'll need to see your code...
K.
-
ok here goes :
there are two functions.. one to draw a Rectangle and one for a circle
the one that works is drawRectangle
code:
// ActionScript Document
degTorad = function(angle){
return angle/180 * Math.PI;
}
function drawCirle (radius,x,y) {
createEmptyMovieClip("circle",1);
circle.lineStyle(2,0xFF0000,100);
trace("hello");
var x1 = x;
var y1 = y;
var ctrlX = x+radius;
var ctrlY = y+radius;
x1 += radius;
circle.moveTo(x1,y1);
x1 -=radius;
y1 +=radius;
circle.curveTo(ctrlX,ctrlY,x1,y1);
ctrlX = x-radius;
x1-=radius;
y1-=radius;
circle.curveTo(ctrlX,ctrlY,x1,y1);
}
function drawRectangle (width,height,round,x,y,rotation){
createEmptyMovieClip("rectangle",1);
rectangle.lineStyle(2,0xFF0000,100);
var r = Math.sqrt(Math.pow(width/2,2)+Math.pow(height/2,2))
var r1 = Math.sqrt(Math.pow(width/2-round,2)+Math.pow(height/2,2));
var r2 = Math.sqrt(Math.pow(width/2,2)+Math.pow(height/2-round,2));
//calculation of important angles
var presAngle= (rotation == undefined) ? 0 : degTorad(rotation);
var alpha1 = Math.atan((height/2-round)/(width/2));
var alpha2 = Math.atan(height/width);
var alpha3 = Math.atan((height/2)/(width/2-round))
/**START HERE -- FIRST CURVE AND LINE**/
presAngle += alpha1;
var x1 = x + Math.cos(presAngle)*r2;
var y1 = y + Math.sin(presAngle)*r2;
rectangle.moveTo(x1,y1);
presAngle-=alpha1;
presAngle+=alpha2;
var ctrlX = x + Math.cos(presAngle)*r;
var ctrlY = y + Math.sin(presAngle)*r;
//drawing the curved line
presAngle -= alpha2;
presAngle += alpha3;
x1 = x + Math.cos(presAngle)*r1;
y1 = y + Math.sin(presAngle)*r1;
rectangle.curveTo(ctrlX,ctrlY,x1,y1);
//drawing line to next curve point
presAngle -= alpha3;
presAngle += Math.PI-alpha3;
x1 = x + Math.cos(presAngle)*r1;
y1 = y + Math.sin(presAngle)*r1;
rectangle.lineTo(x1,y1);
/** SECOND CURVE AND LINE **/
//curved line : again
presAngle += alpha3 - alpha2;
ctrlX = x + Math.cos(presAngle)*r;
ctrlY = y + Math.sin(presAngle)*r;
//drawing it
presAngle += alpha2-alpha1;
var x1 = x + Math.cos(presAngle)*r2;
var y1 = y + Math.sin(presAngle)*r2;
rectangle.curveTo(ctrlX,ctrlY,x1,y1);
//line to next point
presAngle -= (Math.PI -alpha1);
presAngle += (Math.PI +alpha1);
var x1 = x + Math.cos(presAngle)*r2;
var y1 = y + Math.sin(presAngle)*r2;
rectangle.lineTo(x1,y1);
/** THIRD CURVE AND LINE **/
//curved line 3
presAngle -= alpha1;
presAngle += alpha2;
ctrlX = x + Math.cos(presAngle)*r;
ctrlY = y + Math.sin(presAngle)*r;
//draw the curve
presAngle -= alpha2;
presAngle += alpha3;
x1 = x + Math.cos(presAngle)*r1;
y1 = y + Math.sin(presAngle)*r1;
rectangle.curveTo(ctrlX,ctrlY,x1,y1);
//drawing line to next curve point
presAngle -= alpha3;
presAngle += Math.PI-alpha3;
x1 = x + Math.cos(presAngle)*r1;
y1 = y + Math.sin(presAngle)*r1;
rectangle.lineTo(x1,y1);
/**FOURTH CURVE AND LINE**/
//curved line : again
presAngle += alpha3 - alpha2;
ctrlX = x + Math.cos(presAngle)*r;
ctrlY = y + Math.sin(presAngle)*r;
//drawing it
presAngle += alpha2-alpha1;
var x1 = x + Math.cos(presAngle)*r2;
var y1 = y + Math.sin(presAngle)*r2;
rectangle.curveTo(ctrlX,ctrlY,x1,y1);
//line to next point
presAngle -= (Math.PI -alpha1);
presAngle += (Math.PI +alpha1);
var x1 = x + Math.cos(presAngle)*r2;
var y1 = y + Math.sin(presAngle)*r2;
rectangle.lineTo(x1,y1);
}
Thanks for your help,
Manojo
-
And how are you calling that code?
K.
-
here's what on the 1st frame of my move :
code:
#include "drawObjects.as"
drawRectangle(100,200,30,300,300);
drawCircle(20,100,100);
I tried inversing the order, doesn't work either.
thanks,
Manojo
-
Well, a couple of things I notice in your code - first, you have a typo in your circle function - drawCirle should be drawCircle
Secondly, both your circle and rectangle clips are being created at the same depth (1) - so only one or the other will exist at any given time...
K
-
-
Hi,
sorry for that.. I really should have checked the typo error. As for the levels, is that logical to what is possible when you draw these figures? -> indeed, you can have multiple MCs at the same level.
thanks,
Manojo
-
You can only have one movieclip per depth level...see:
http://livedocs.macromedia.com/flash....html#wp122014
K.
-
hi,
thanks for that info,
Manojo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|