Search code examples
actionscript-3geometrypreloaderdocument-class

dynamically draw circle preloader error 1061 when in document class


I found a tutorial on how to make a dynamic unfilled and filled circle. that will take input from a slider to dertermine how much of the circle is drawn. I wanted to use this for a preloader. Unlike the author I would like to use it inside of a document class. I am getting 1061: Call to a possibly undefined method createEmptyMovieClip through a reference with static type document. and 1120: Access of undefined property circ1. The second is caused from the first. How would I get this to work in my document class? Thanks in advance!

//original code
// x: circles center x, y: circles center y
// a1: first angle, a2: angle to draw to, r: radius
// dir: direction; 1 for clockwise -1 for counter clockwise
MovieClip.prototype.CircleSegmentTo = function(x, y, a1, a2, r, dir) {
     var diff = Math.abs(a2-a1);
     var divs = Math.floor(diff/(Math.PI/4))+1;
     var span = dir * diff/(2*divs);
     var rc = r/Math.cos(span);
     this.moveTo(x+Math.cos(a1)*r, y+Math.sin(a1)*r);
     for (var i=0; i<divs; ++i) {
          a2 = a1+span; a1 = a2+span;
          this.curveTo(
               x+Math.cos(a2)*rc,
               y+Math.sin(a2)*rc,
               x+Math.cos(a1)*r,
               y+Math.sin(a1)*r
          );
     };
     return this;
};

// empty
this.createEmptyMovieClip("circ1",1);
circ1._x = 100;
circ1._y = 150;
circ1.radius = 35;

circ1.onEnterFrame = function(){
    this.clear();
    var endAngle = 2*Math.PI*percentLoaded;
    var startAngle = 0;
    if (endAngle != startAngle){
        this.lineStyle(2,0,100);
        this.CircleSegmentTo(0, 0, startAngle, endAngle, this.radius, -1);
    }
}

//filled
this.createEmptyMovieClip("circ2",2);
circ2._x = 220;
circ2._y = 150;
circ2.radius = 35;
/* code in tutorial i left out since its for a second filled in circle
circ2.onEnterFrame = function(){
    this.clear();
    var endAngle = 2*Math.PI*slider.value/100;
    var startAngle = 0;
    if (endAngle != startAngle){
        this.lineStyle(2,0,100);
        this.beginFill(0xFF9999,100);
        this.lineTo(this.radius,0);
        this.CircleSegmentTo(0, 0, startAngle, endAngle, this.radius, -1);
        this.lineTo(0,0);
        this.endFill();
    }
}
*/

Solution

  • That code you got was made using Actionscript 2, and you're building it for Actionscript 3, so you have to either recode it to Actionscript 3 or compile it for AS2.