dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [Help][AS2-AS3] Fast Track

  1. #1
    CostomJunky Xploder's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    635

    [Help][AS2-AS3] Fast Track

    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:
    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);
    		}
    	}
    }
    'uint' stands for unsigned integer and they use it in the docs. This is the error I'm getting for the polygon function:
    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()
    see working code in AS2 below...
    file: graphics_c.as
    AS2:
    Code:
    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;
    	}
    }
    file: graphics.fla
    script in actions frame
    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);
    Anyone with solutions or their own AS2-AS3 migration trouble please post below... that way we'll get a collection of known issues.
    Thanks,

    Xploder

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    This is not a migration issue, it is a syntax error, or an oversight on your part.

    This function

    Code:
    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);
    		}
    Should be:

    Code:
    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.graphics.moveTo(arr[i], arr[i+1]);
    				} else {
    					child.graphics.lineTo(arr[i], arr[i+1]);
    					if (i == 6 || i == 2) {
    						child.graphics.lineStyle(thick, color, 0);
    					} else {
    						child.graphics.lineStyle(thick, color);
    					}
    				}
    			}
    			child.graphics.endFill();
    			addChild(child);
    		}
    Changes are highlighted in bold

  3. #3
    CostomJunky Xploder's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    635
    ah thanks, its not giving any errors, but how do I make it show up now.
    Btw, I'm not saying its migration issue, its just I don't know the art of migration .

    Edit
    Ah ok it works:
    Code:
    package{
    	import flash.display.*;
    	import flash.events.MouseEvent;
    	public class graphics_c extends MovieClip {
    		private var color:uint = 0x000000;
        	private var thick:uint = 1;
    		private var fill:uint = 0xFEC878;
    		public function graphics_c(){
    			var arr:Array = new Array(0,0,0,50,50,50,50,0);
    			fillCircle(100,100,10);
    			polygon(arr);
    		}	
    		public function fillCircle(x:int,y:int,r:uint):void {
    			var child:Sprite = new Sprite();
    	    	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:Sprite = new Sprite();
    			child.graphics.beginFill(fill);
    			child.graphics.lineStyle(thick, color);
    			for (var i = 0; i<arr.length; i += 2) {
    				if (i == 0) {
    					child.graphics.moveTo(arr[i], arr[i+1]);
    				} else {
    					child.graphics.lineTo(arr[i], arr[i+1]);
    					if (i == 6 || i == 2) {
    						child.graphics.lineStyle(thick, color, 0);
    					} else {
    						child.graphics.lineStyle(thick, color);
    					}
    				}
    			}
    			child.graphics.endFill();
    			addChild(child);
    		}
    	}
    }
    Last edited by Xploder; 08-10-2006 at 10:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center