Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:18:16+00:00 2026-05-27T01:18:16+00:00

I’m trying to find a good way to use TweenMax and flash’s drawing class

  • 0

I’m trying to find a good way to use TweenMax and flash’s drawing class together, but it always bogs down and crashes the flash player, and I can’t really figure out what’s going wrong. Really all I want to do is make sure that when two (or more) circles, connected by a line, move, that the line between them follows. This is my code:

import com.greensock.TweenMax;

var sw = stage.stageWidth;
var sh = stage.stageHeight;
var cr = 3; //circle radius
var moveRange = 20;
var circleColor = 0xcccccc;
var numCircles = 2;
var circleArray = [];
var lineCanvas:Sprite = new Sprite();
addChild(lineCanvas);
var lineColor = 0xe9e9e9;
var lineWeight = 1;

function init(){
    drawCircle();
}

function drawCircle(){
    for (var i = 0; i<numCircles; i++){
        var xPos = randomRange(cr, sw-cr);
        var yPos = randomRange(cr, sh-cr);
        var newCircle:Shape = new Shape();
        newCircle.graphics.beginFill(circleColor);
        newCircle.graphics.drawCircle(0,0,cr);
        newCircle.x = xPos;
        newCircle.y = yPos;
        newCircle.graphics.endFill();
        circleArray.push(newCircle);
        addChild(newCircle);
    }
    drawLine();
}

function drawLine(){
    for (var i = 0; i<numCircles-1; i++){
        lineCanvas.graphics.clear();
        lineCanvas.graphics.lineStyle(lineWeight,lineColor);
        lineCanvas.graphics.moveTo(circleArray[i].x,circleArray[i].y);
        lineCanvas.graphics.lineTo(circleArray[i+1].x,circleArray[i+1].y);
    }
    moveCircle();
}

function moveCircle(){
    for (var i = 0; i<numCircles; i++){
        var curX = circleArray[i].x;
        var curY = circleArray[i].y;
        var moveX = randomRange(curX-moveRange,curX+moveRange);
        var moveY = randomRange(curY-moveRange,curY+moveRange);
        //TweenMax.to(circleArray[i],.5, { x: moveX, y: moveY, onUpdate:drawLine });
    }
}

function randomRange(minNum:Number, maxNum:Number):Number {  
    return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);  
}

init();

Is there a better way to do this? Should I not be using a tweening library?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:18:16+00:00Added an answer on May 27, 2026 at 1:18 am

    because mheavers asked me, i put together a little example using an ENTER_FRAME listener to animate the circles manually.

    i got two classes:

    package
    {
        import flash.filters.BlurFilter;
        import flash.events.Event;
        import flash.display.Sprite;
    
        [SWF(backgroundColor="#000000", frameRate="60", width="960", height="600")]
        public class Main extends Sprite
        {
            private var numCircles:int = 2;
            private var circles:Vector.<Circle>;
            private var lineCanvas:Sprite;
            private var lineColor:uint = 0xe9e9e9;
            private var lineWeight:int = 1;
            private var blur:BlurFilter;
    
            public function Main()
            {
                init();
            }
    
            private function init():void
            {
                circles = new Vector.<Circle>();
                blur = new BlurFilter();
    
                lineCanvas = new Sprite();
                addChild(lineCanvas);
    
                drawCircle();
    
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
            }
    
            private function drawCircle():void
            {
                for (var i:int = 0; i < numCircles; i++)
                {
                    var newCircle:Circle = new Circle();
                    circles.push(newCircle);
                    addChild(newCircle);
                }
                drawLine();
            }
    
            private function drawLine():void
            {
                var circle:Circle;
                var nextCircle:Circle;
                for (var i:int = 0; i < circles.length-1; i++)
                {
                    circle = circles[i];
                    nextCircle = circles[i+1];
    
                    //lineCanvas.graphics.clear();
                    lineCanvas.graphics.lineStyle(lineWeight, lineColor);
                    lineCanvas.graphics.moveTo(circle.x, circle.y);
                    lineCanvas.graphics.lineTo(nextCircle.x, nextCircle.y);
                }
            }
    
            private function onEnterFrame(event:Event):void
            {
                // update circles
                var circle:Circle;
                for (var i:int = 0, len:int = circles.length; i < len; i++)
                {
                    circle = circles[i];
                    circle.move();
                }
    
                drawLine();
            }
        }
    }
    

    and another one for the circle:

    package
    {
        import flash.events.Event;
        import flash.display.Shape;
    
        public class Circle extends Shape
        {
            public var targetx:Number;
            public var targety:Number;
    
            private var circleColor:uint = 0xcccccc;
            private var cr:int = 3;
            private var moveRange:int = 150;
    
            public function Circle()
            {
                graphics.beginFill(circleColor);
                graphics.drawCircle(0, 0, cr);
                graphics.endFill();
    
                addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
            }
    
            public function move():void
            {
                var absx:Number = Math.abs(targetx-x);
                var absy:Number = Math.abs(targety-y);
    
                if (absx < 1 && absy < 1)
                {
                    targetx = randomRange(x - moveRange, x + moveRange);
                    targety = randomRange(y - moveRange, y + moveRange);
    
                    if (targetx >= stage.stageWidth)
                    {
                        targetx = stage.stageWidth - moveRange;
                    }
                    else if (targetx <= 0)
                    {
                        targetx = moveRange;
                    }
    
                    if (targety >= stage.stageHeight)
                    {
                        targety = stage.stageHeight - moveRange;
                    }
                    else if (targety <= 0)
                    {
                        targety = moveRange;
                    }
                }
                else
                {
                    x += (targetx - x) * 0.125;
                    y += (targety - y) * 0.125;
                }
            }
    
    
            private function onAddedToStage(event:Event):void
            {
                removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    
                // position circle on stage
                x = targetx = randomRange(cr, stage.stageWidth - cr);
                y = targety = randomRange(cr, stage.stageHeight - cr);
            }
    
            private function randomRange(minNum:Number, maxNum:Number):Number
            {
                return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
            }
        }
    }
    

    looks sth like this:

    example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.