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 7811165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:03:46+00:00 2026-06-02T04:03:46+00:00

I’m trying to write the base code for a graphing document that shows a

  • 0

I’m trying to write the base code for a graphing document that shows a value on the graph each time an int is pushed into an array. Here is the code-

import flash.display.Shape;
import flash.display.MovieClip;
import flash.display.Sprite;
var myShape:Shape = new Shape();
myShape.graphics.lineStyle(2, 0x990000, 2);
var max:Number = 0;
var graph:Array = new Array();
var container:Sprite = new Sprite();
var redrawGraph = setInterval(reDraw,1000);
function reDraw()
    {
        while (container.numChildren)
        {
            container.removeChildAt(0);
        }
        graph.push(randomNum());
        graph.reverse();
        for (var ints in graph)
        {
        if (graph[ints] > max)
        {
            max = graph[ints];
        }
    }
for (var i:Number = 0; i < graph.length-1; i++)
{
    myShape.graphics.moveTo(550-i*50, (max – graph[i])*20);
    myShape.graphics.lineTo(550-(i+1)*50, (max – graph[i+1])*20);
    container.addChild(myShape);
}
this.addChild(container);
graph.reverse();
}

function randomNum():int
{

return Math.floor(Math.random() * 11);`

}

Except the issue i’m having is I end up with the graph overlapping the previous one, the part where it should be removing the old graph shapes doesn’t seem to be working…and I can’t figure out why.

Any help would be appreciated.

(sorry about the formatting…it wouldn’t work properly

  • 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-06-02T04:03:48+00:00Added an answer on June 2, 2026 at 4:03 am

    You have a misunderstanding of the difference between display objects hierarchy and manipulating the graphics object of a display object.

    You are using setInterval to call a reDraw callback.

    In the reDraw callback, you are using graphics.moveTo and graphics.lineTo to draw your graph. However, every frame you are constantly drawing to the same “canvas”, the same Sprite: myShape.

    Adding and removing the display objects from each other is unnecessary. In this case, you only need to add the display objects once. And then on each refresh, clear the canvas and start drawing again.

    For example, consider the following:

        var myShape:Shape;
        var graph:Array;
        var container:Sprite = new Sprite();
    
        myShape = new Shape();
        graph = new Array();
        var redrawGraph:int = setInterval(reDraw,1000);
    
        container.addChild(myShape);
        this.addChild(container);
    

    Here I am creating a the shape, putting the shape into the container, and then adding the container to the root display object, and thats pretty much it. And then…

        private function reDraw():void {
            myShape.graphics.clear();
            myShape.graphics.lineStyle(2, 0x990000, 2);
    
            graph.unshift(randomNum());
    
            var i:uint, len:uint = graph.length, max:int = 0;
    
            for (i=0; i< len; i++) {
                max = Math.max(graph[i], max);
            }
    
            for (i = 0; i < len; i++)
            {
                myShape.graphics.moveTo(550-i*50, (max - graph[i])*20);
                myShape.graphics.lineTo(550-(i+1)*50, (max - graph[i+1])*20);
    
            }
        }
    

    Then here, notice that I am not removing or adding anything to the display tree, the tree is already organized the way that I want. All I’m doing on a redraw is clearing my shape, and then redrawing it the way that I want it to be displayed.

    Sometimes you do need to manipulate the display hierarchy, but this is not one of those times.

    See here for a working example…

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.