Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Draw with Flash

  1. #1
    Join Date
    Jul 2006
    Posts
    139
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Draw with Flash

    Hello all:

    I have simple problem. I am very new to flash and I need a simple program (I thought doing it in flash would be very simple!) that would draw a rectangle or circle and move it with the cursor (when mouse button pressed down). Does anyone know of an example that I can take a look at (googling didnt help). I would really appreciate any help.

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Do you want to have an animation play of the rectangle being drawn and then move it have it move with the cursor or do you just want a rectangle to move with the cursor.

    Not sure if the drawing of the rectangle is supposed to be done before or after the movie is compiled.

  3. #3
    Join Date
    Jul 2006
    Posts
    139
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question

    Thanks for the reply. Its actually very simple. No animation I would input the width and height of the rectangle at the input box and when click draw it will draw the image and then I want to press the left mouse button and move the drawing.
    Last edited by neo_philiac; 03-19-2008 at 07:47 PM.

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Ahh, that's fairly easy...

    I'll make up a quick .swf for you, with comments. It's easier to read the code than for me to explain it.

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Ok here you are....

    I've made something up. It's ver basic, but should be good to learn from. I've commented out as much as I thought was necessary.

    Demo
    Source

  6. The Following User Says Thank You to Medyman For This Useful Post:

    evan (03-20-2008)

  7. #6
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    Is this actionscript 2.0 or 3.0?

  8. #7
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by evan View Post
    Is this actionscript 2.0 or 3.0?
    It's 2.0

  9. #8
    Join Date
    Jul 2006
    Posts
    139
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Hello I am back ! Here is what I have been working on:

    Everything is working the way I want but I need three things

    1. The bouncing effect needs angular movement (so, if I say it to bounce along the 30 deg it should bounce along the 30 degree line)

    2. I need the bouncing to stop whenever I create a new line.

    3. I need to draw the line and make the registration point in the middle. (in other words when I hit rotate it should rotate along the center. It does that now but its a little bit off.)

    I am a noob so please excuse my way of coding. (hey! I am learning!)



    Code:
    #include "mc_tween2.as"
    
    
    /* Initial Setup
       When the movie first loads, we want the rectangle to have a width & height of "0"
       If you want a different height, adjust the values below.
       
       Sample syntax:  rect_mc.resizeTo (width, height, time (in seconds), animation type);
       
       We also want to set the text inputs to show that the dimensions are 0 x 0  */
       
       rect_mc.resizeTo(0, 0, .5, "easeOutQuad");  //Initial Rectangle Resize Function
       width_text.text = "10";   // Width text field
       height_text.text = "100";  // Height text field rot_text
       rot_text.text = "0";
    
       	//Background color Radio Button.
    	
    	rb_shape_ln.data = "line";	
    	rb_shape_cr.data = "circle";
    
    	//Create new movie
    	
    	createEmptyMovieClip("tmp_mc", 1);
    	
    	
    	line1_mc.moveTo(0,0);
    	
    	//Background color Radio Button.
    	
    	base_mc.cacheAsBitmap = true;
    	rb_color_w.data = "0xFFFFFF";	
    	rb_color_b.data = "0x000000";
    
    	//Background color Radio Button.
    	
    	rb_shape_ln.data = "line";	
    	rb_shape_cr.data = "circle";
    
    
       /* createBtn.onRelease function - activates when you click on the "Create" button */
       createBtn.onRelease = function() {
    	  
    	text_mc.text = shapeGroup.selectedData;
    	  
    	  this.stop();
    	  tmp_mc.clear();
    	  base_mc.clear();
    	  var rectWidth = width_text.text;   // Read in what's in the text input
    	  var rectHeight = height_text.text;
    	  var rectRot = rot_text.text;
    	  var colorData = (Number(baseColorGroup.selectedData));
    	  var tmp;
      	  base_mc.opaqueBackground=colorData;
    
    	  //Selecting Fill color
    	  
    	  if (colorData == 16777215){
    		tmp = 0x000000;
    	  }
    	  else {
    		tmp = 0xFFFFFF;
    	  }
    	  
    	  if (shapeGroup.selectedData == "line"){
    		
    		tmp_mc.lineStyle(rectWidth,tmp,100);
    	  	tmp_mc.moveTo(0, (rectHeight/2));
    	  	tmp_mc.lineTo(0, (-(rectHeight)));
    	  	tmp_mc._y = Stage.height/2;
    	  	tmp_mc._x = Stage.width/2;
    	  	tmp_mc.rotateTo(rectRot, .5, "linear");
    	  }
    	  
    	  else if (shapeGroup.selectedData == "circle"){
    	   	// use the method to draw a circle in movieclip c 
    	   	// at x=100, y=100 with a 70-pixel radius
    	   	tmp_mc.beginFill(tmp, 100);
    	   	tmp_mc.drawCircle(rectWidth, Stage.height/2, Stage.height/2);
    	   	tmp_mc.endFill();
    	  }
    	  else {
    		  text_mc.text = "Please Select Shape";
    	  } 
    
       }
    
    /*  On press rotates */
    
    		rot_Button.onRelease = function() {  
    		var i = 0;
    		while (i<=1000){
    	    tmp_mc.rotateTo(i,3,"linear");
    		i +=1;
    		}
    		
        }
       
    /*  On press bounces the shape */
    
    		bounce_Button.onRelease = function() {  
    
    		
    		var gravity = 100;
    		var floor = tmp_mc._y+200;
    		var Vy = 0;
    		//tmp_mc._y = 40;
    
    		tmp_mc.onEnterFrame = function() {
    		Vy += gravity;
    		this._y += Vy/4;
    
    		if (this._y > floor) {
    		this._y = floor;
    		Vy = -Vy;
    	}
       }
    		
     }
    
    /*  rect_mc.onPress  function - activates when you click on the rectangle */
    
        	tmp_mc.onPress = function() {
    		this.startDrag();
    	}
    	
    /*  rect_mc.onRelease  function - activates when you release the mouse */
    
    		tmp_mc.onRelease = function() {
    		this.stopDrag();
    	}
    // Draw circle method
    
    MovieClip.prototype.drawCircle = function (r, x, y) {
       var TO_RADIANS:Number = Math.PI/180;
       // begin circle at 0, 0 (its registration point) -- move it when done
       this.moveTo(0, 0);
       this.lineTo(r, 0);
    
       // draw 12 30-degree segments 
       // (could do more efficiently with 8 45-degree segments)
       var a:Number = 0.268;  // tan(15)
       for (var i=0; i < 12; i++) {
          var endx = r*Math.cos((i+1)*30*TO_RADIANS);
          var endy = r*Math.sin((i+1)*30*TO_RADIANS);
          var ax = endx+r*a*Math.cos(((i+1)*30-90)*TO_RADIANS);
          var ay = endy+r*a*Math.sin(((i+1)*30-90)*TO_RADIANS);
          this.curveTo(ax, ay, endx, endy);	
       }
       this._x = x;
       this._y = y;   
    }

  10. #9
    Join Date
    Jul 2006
    Posts
    139
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Any Help? Please !!

  11. #10
    Join Date
    Jul 2006
    Posts
    139
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Sorry it took me a while. Here is the fla file.

    here you go... hey, Medyman can you take a look at this?

    http://www.mntp.pitt.edu/Personal%20Pages/personal.html

    Thanks

Bookmarks

Posting Permissions

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