
Copy link to clipboard
Copied
Hello,
I want to start building some prebuild shapes, like a star, cross, heart, and some more with code.
Does anyone know if there is already something like this ? A library with custom sprites or shapes?
And should i create these graphics extending the sprite or shape class? I read that shapes would
be better for performance?
Regards,
Chris.
1 Correct answer
use google to search.
i know there is public php code for some shapes and the code's not much different for actionscript.
use shapes. there's not much difference, if any, in performance but you won't be using any of the properties/methods of the sprite class so you may as well use the shape class.
Copy link to clipboard
Copied
use google to search.
i know there is public php code for some shapes and the code's not much different for actionscript.
use shapes. there's not much difference, if any, in performance but you won't be using any of the properties/methods of the sprite class so you may as well use the shape class.

Copy link to clipboard
Copied
thanks Kglad, i did some search on this topic, but could not find
prebuild shapes in Flash. So when i want to set properties of a shape, then
it is better to use a Sprite?
var myShape:CustomArrow = new CustomArrow();
myShape.color = 0xFF0000;
myShape.arrowSize = 14;
myShape.arrowlineWidth = 200;
This is the idea of using dynamic Shapes.
Regards,
Chris.
Copy link to clipboard
Copied
yes, use shapes. but that would look more like:
package{
import flash.display.shape;
public class CustomArrow extends Shape{
//etc
var ca:CustomArrow=new CustomArrow();
//etc
// and heres an as2 start/polygon drawing function for you. the groinRatio is the ratio of the stars groin to its radius. if that's 1, you'll have a polygon instead of a star.
function drawPolyStar(mc:MovieClip, x1:Number, y1:Number, x2:Number, y2:Number, starPoints:Number, groinRatio:Number, lineA:Array, fillA:Array):Void {
var piHalf:Number = Math.PI/2;
var ang:Number = Math.PI*2/starPoints;
var w2:Number = Math.abs(x2-x1)/2;
var h2:Number = Math.abs(y2-y1)/2;
var rad:Number = h2;
if (lineA[0]) {
mc.lineStyle(lineA[0],lineA[1],lineA[2]);
}
if (fillA[0]) {
mc.beginFill(fillA[0],fillA[1]);
}
if (lineA == undefined && fillA == undefined) {
mc.lineStyle(1,0x000000);
}
// start at top
mc.moveTo(w2,0);
for (var i:Number = 0; i<starPoints; i++) {
var ptAng:Number = -piHalf+i*ang;
mc.lineTo(w2+(h2*w2/h2)*Math.cos(ptAng),h2+rad*Math.sin(ptAng));
var ptGroin:Number = ptAng+ang/2;
mc.lineTo(w2+groinRatio*(h2*w2/h2)*Math.cos(ptGroin),h2+groinRatio*rad*Math.sin(ptGroin));
}
mc.endFill();
}

Copy link to clipboard
Copied
Many thanks Kglad! This is a very helpfull script!!!
Copy link to clipboard
Copied
you're welcome.

