Previously I coded in AS2 now I'm trying to make the switch to AS3. I checked out the migration doc but am still stumped on this one,
file: graphics_c.as
AS3:'uint' stands for unsigned integer and they use it in the docs. This is the error I'm getting for the polygon function:Code:package{ import flash.display.DisplayObject; import flash.display.Graphics; import flash.display.Shape; import flash.display.Sprite; public class graphics_c extends Sprite { private var color:uint = 0x000000; private var thick:uint = 1; private var fill:uint = 0xFEC878; public function graphics_c(){} public function fillCircle(x:int,y:int,r:uint):void { var child:Shape = new Shape(); child.graphics.beginFill(fill); child.graphics.lineStyle(thick, color); child.graphics.drawCircle(x, y, r); child.graphics.endFill(); addChild(child); } public function polygon(arr:Array):void { var child:Shape = new Shape(); child.graphics.lineStyle(thick, color); child.graphics.moveTo(arr[0], arr[1]); child.graphics.beginFill(fill); for (var i = 0; i<arr.length; i += 2) { if (i == 0) { child.moveTo(arr[i], arr[i+1]); } else { child.lineTo(arr[i], arr[i+1]); if (i == 6 || i == 2) { child.lineStyle(thick, color, 0); } else { child.lineStyle(thick, color); } } } child.graphics.endFill(); addChild(child); } } }
see working code in AS2 below...Code:ReferenceError: Error #1069: Property moveTo not found on flash.display.Shape and there is no default value. at graphics_c/polygon() at Timeline0_8c923c31f95ac242a5edb0f9f206ae/::frame1()
file: graphics_c.as
AS2:file: graphics.flaCode:class graphics_c extends MovieClip { var mc; var color:String; var thick:Number; var fill:String; public function graphics_c(depth:Number) { mc = _root.createEmptyMovieClip("test1", depth); color = "0x000000"; thick = 1; fill = "0xFEC878"; } public function fillCircle(r:Number, x:Number, y:Number) { var styleMaker:Number = 22.5; mc.moveTo(x+r, y); mc.lineStyle(thick, color); mc.beginFill(fill); var style:Number = Math.tan(styleMaker*Math.PI/180); for (var angle:Number = 45; angle<=360; angle += 45) { var endX:Number = r*Math.cos(angle*Math.PI/180); var endY:Number = r*Math.sin(angle*Math.PI/180); var cX:Number = endX+r*style*Math.cos((angle-90)*Math.PI/180); var cY:Number = endY+r*style*Math.sin((angle-90)*Math.PI/180); mc.curveTo(cX+x, cY+y, endX+x, endY+y); } mc.endFill(); } public function polygon(mc, arr:Array) { var len = arguments.length; mc.lineStyle(thick, color); mc.beginFill(fill); for (var i = 0; i<arr.length; i += 2) { if (i == 0) { mc.moveTo(arr[i], arr[i+1]); } else { mc.lineTo(arr[i], arr[i+1]); if (i == 6 || i == 2) { mc.lineStyle(thick, color, 0); } else { mc.lineStyle(thick, color); } } } mc.endFill(); return mc; } }
script in actions frame
Anyone with solutions or their own AS2-AS3 migration trouble please post below... that way we'll get a collection of known issues.Code:var gfx:graphics_c = new graphics_c(); var arr:Array = new Array(0,0,0,50,50,50,50,0); gfx.fillCircle(0,0,10); gfx.polygon(arr);
Thanks,
Xploder




Reply With Quote