dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: drawing within my component

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    drawing within my component

    I've made a component that has a draw method that should draw a visual representation of the object and needs to update.

    Right now I have a sprite that I draw to and it works but I think I'm doing this wrong and am making multiple sprites.

    When I try to move the canvas creation outside of the draw function I cannot draw on it.

    Here's a snippet of what I'm doing
    Code:
    public function draw():void {
    			var y1:int = 18;
    			var y2:int = 50;
    			var y3:int = 80;
    			//redraw visual representation of die
    			var canvas:Sprite = new Sprite;
    			//draw box
    			canvas.graphics.beginFill(_bg, 1);
    			canvas.graphics.lineStyle(1, 0, 1, false, "normal", null, "round");
    			canvas.graphics.drawRoundRect(0, 0, 100, 100, 9);
    			
    			var y:int = 5;
    			//draw dots
    					
    			var fillType:String = GradientType.RADIAL;
    			var colors:Array = [0x808080, 0x000000];
    			var alphas:Array = [1, 1];
    			var ratios:Array = [0, 255];
    			canvas.graphics.lineStyle(.4, 0xffffff, 1);
    			canvas.graphics.beginGradientFill(fillType, colors, alphas, ratios);
    			if (_number == 1) {
    				canvas.graphics.drawCircle(y2,y2, 10);
    			}
    			if (_number == 2) {
    				canvas.graphics.drawCircle(y1, y1, 10);
    				canvas.graphics.drawCircle(y3, y3, 10);
    			}
    			if (_number == 3) {
    				canvas.graphics.drawCircle(y1, y1, 10);
    				canvas.graphics.drawCircle(y2, y2, 10);
    				canvas.graphics.drawCircle(y3, y3, 10);
    			}
    			if (_number == 4) {
    				canvas.graphics.drawCircle(y1, y1, 10);
    				canvas.graphics.drawCircle(y1, y3, 10);
    				canvas.graphics.drawCircle(y3, y1, 10);
    				canvas.graphics.drawCircle(y3, y3, 10);
    			}
    			if (_number == 5) {
    				canvas.graphics.drawCircle(y1, y1, 10);
    				canvas.graphics.drawCircle(y1, y3, 10);
    				canvas.graphics.drawCircle(y2, y2, 10);
    				canvas.graphics.drawCircle(y3, y1, 10);
    				canvas.graphics.drawCircle(y3, y3, 10);
    			}
    			if (_number == 6) {
    				canvas.graphics.drawCircle(y1, y1, 10);
    				canvas.graphics.drawCircle(y1, y2, 10);
    				canvas.graphics.drawCircle(y1, y3, 10);
    				canvas.graphics.drawCircle(y3, y1, 10);
    				canvas.graphics.drawCircle(y3, y2, 10);
    				canvas.graphics.drawCircle(y3, y3, 10);
    			}
    			addChild(canvas);
    		}
    I'm new to the whole AS3 thing and I also realize I should probably make a circle object and be using it instead. Any suggestions of a better approach here?

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    When you say outside what do you mean and which part?
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I've basically figured it out... I just need to move my drawing sprite out of the draw method and create it in the constructor then clear it when redrawing the sprite.

    This was my first try at creating an AS3 class as a learning exersize....
    here it is working http://bretlanius.com/flash/d2test.html code is there as well.

    I realize there are numerous areas for improvement, including how I draw it. I am considering rewriting it using a class of dot that I put 7 of them on the display sprite and just hide/show the correct one based on the number.
    Last edited by blanius; 02-23-2008 at 06:54 PM.

  4. #4
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    AMazing O_O! That dice has like 10 different 6's with different colors O_O

    :P good job on it anywho ^^

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