A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: A script to make a movieclip move in a circle

  1. #1
    Member
    Join Date
    Feb 2006
    Posts
    62

    A script to make a movieclip move in a circle

    Hey this is my script to draw a rectangle. I want to write a script for it to move in a circle of certain diameter at a certain velocity. Is this possible?

    Code:
    this.createEmptyMovieClip("mEye001", this.getNextHighestDepth());
    mEye001.lineStyle(0, 0xFF0000);
    mEye001.beginFill(0xFFFF00, 100);
    mEye001.lineTo(100, 0);
    mEye001.lineTo(100, 100);
    mEye001.lineTo(0, 100);
    mEye001.lineTo(0, 0);
    mEye001.endFill();
    mEye001._x = 100;
    mEye001._y = 100;

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    This post should help.

  3. #3
    Member
    Join Date
    Feb 2006
    Posts
    62
    i found this script for moving the movieclip in the link you gave me, however, i can figure out how to put them together...

    Code:
    onClipEvent(load)
    {
      cx = Stage.width/2; // coords of center of circle (center of screen, in this case)
      cy = Stage.height/2;
    
      rad = 100; // radius of circle
    
      speed = 6; // speed of travel (seconds to make a complete circuit)
      speedScale = (0.001*2*Math.PI)/speed;
    }
    
    onClipEvent(enterFrame)
    {
      var angle = getTimer()*speedScale;
      this._x = cx + Math.sin(angle)*rad;
      this._y = cy + Math.cos(angle)*rad;
    }

  4. #4
    Member
    Join Date
    Feb 2006
    Posts
    62
    may i need to add a listener somewhere... ideas? the output says "**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 19: Expected a field name after '.' operator.
    mEye001.onClipEvent(load) {"
    Last edited by 72monkeys; 05-02-2006 at 08:43 AM.

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Code:
    var centerX:Number = Stage.width/2; // coords of center of circle (center of screen, in this case)
    var centerY:Number = Stage.height/2;
    
    var radius:Number = 100; // radius of circle
    var radians:Number = 0;
    var speed:Number = 0.1;
    
    
    makeSquare();
    
    var mcSquare:MovieClip;
    var nMove:Number;
    
    function makeSquare():Void{
    	
    mcSquare = _root.createEmptyMovieClip("mEye001", _root.getNextHighestDepth());
    mEye001.lineStyle(0, 0xFF0000);
    mEye001.beginFill(0xFFFF00, 100);
    mEye001.lineTo(100, 0);
    mEye001.lineTo(100, 100);
    mEye001.lineTo(0, 100);
    mEye001.lineTo(0, 0);
    mEye001.endFill();
    mEye001._x = 100;
    mEye001._y = 100;
    
    nMove = setInterval(mover, 1000/24);
    }
    
    
    function mover():Void{
    	mcSquare._x = centerX + radius * Math.cos(radians);
    	mcSquare._y = centerY + radius * Math.sin(radians);
    	radians += speed;
    	
    	
    	
    	
    	
    	}
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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