0

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();
    }
}
*/
Yamiko
  • 5,303
  • 5
  • 30
  • 52

1 Answers1

0

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.

felipemaia
  • 3,381
  • 1
  • 16
  • 14
  • I recently started actionscript so I dont know what I would have to change since i never used 2.0. Can you possibly tell me what parts I need to rewrite? – Yamiko Oct 31 '11 at 18:08
  • pretty much all of it. most of it is syntax (no underscores before native property names, no event callbacks in AS3, graphic calls exist in a graphics sub property in AS3, etc...) its gonna take a basic understanding of AS2 and AS3 to convert – gthmb Oct 31 '11 at 18:31
  • honestly I dont want to learn as2 just for this. Ill do something different for a preloader and make this in as3 when I'm more familiar with action script. thx for the input. – Yamiko Nov 01 '11 at 01:29