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

  • Home
  • SEARCH
  • 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 6100845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:25:56+00:00 2026-05-23T13:25:56+00:00

I’m new to actionscript. What I’m tryin to do is simulate traffic flow near

  • 0

I’m new to actionscript. What I’m tryin to do is simulate traffic flow near a 2 lane intersection, following Wolfram’s rule 184. To begin with, I’m trying to create a grid (8×8 of which the intersection is between the middle two rows and the middle two columns, like a plus sign) whose cells have the following attributes:

color = white;
car = false;
when clicked:
 color = red;
 car = true (a car is present);

So, after the user clicks cells to position the cars initially and presses the start button, the simulation will begin.

Here’s my code so far (apologies for incorrect formatting):

class Main 
{
private var parent:MovieClip;

public static function main(mc:MovieClip) 
{
    var app = new Main(mc);
}

public function Main(mc:MovieClip) 
{
    this.parent = mc;

    //grid settings
    var Cell:MovieClip = mc.createEmptyMovieClip("cell", mc.getNextHighestDepth());
    var x:Number = 0;
    var y:Number = 0;
    var color:Number = 0xffffff;
    var car:Boolean = false;
    for (y = 0; y < 3 * Stage.height / 8; y += Stage.height / 8)
    {
        for (x = 3*Stage.width/8; x < 5*Stage.width/8; x+=Stage.width/8)
        {
            UI.drawRect(Cell, x, y, (Stage.width / 8) - 5, (Stage.height / 8) - 5, color, 100);
        }
    }
    for (y = 3*Stage.height/8; y < 5 * Stage.height / 8; y += Stage.height / 8)
    {
        for (x = 0; x < Stage.width; x+=Stage.width/8)
        {
            UI.drawRect(Cell, x, y, (Stage.width / 8)-5, (Stage.height / 8)-5, color, 100);
        }
    }
    for (y = 5*Stage.height/8; y < Stage.height; y += Stage.height / 8)
    {
        for (x = 3*Stage.width/8; x < 5*Stage.width/8; x+=Stage.width/8)
        {
            UI.drawRect(Cell, x, y, (Stage.width / 8)-5, (Stage.height / 8)-5, color, 100);
        }
    }
    Cell.onMouseDown()
    {
        Cell.color = UI.RED;
        Cell.car = true;
    }
}
}

I know there’s quite a few things gone wrong here. First of all, the cell color doesn’t change on mouse down. Do i need to make movie clip for each cell in the for loops? I think it would be easier to make a grid of objects with given attributes, but i don’t know how to do that. Would really appreciate if someone helps me out.

  • 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-23T13:25:57+00:00Added an answer on May 23, 2026 at 1:25 pm

    From what I can tell, issue with your current approach is that using drawRect() literally draws pixels on to the stage, which means you’ll have no reference to those shapes in future frames. right now, you’ve got one MovieClip that has been drawn many times. What you need is a lot of MovieClips so you have a reference to each cell that you can update/edit every frame.

    Your best bet is to do the following (I’ll just provide pseudo because I’m a bit shaky on AS2 syntax):

    A) Create an array to hold all of the Cells. Call it:

    var Cells:Array = new Array();
    

    B) During each step of the loops in your constructor, do 4 things.

    1) Create a new MovieClip `var tempCell:MovieClip = new MovieClip();

    2) Draw a rectangle on to each MovieClip: A tutorial for the graphics API in AS2 http://www.actionscript.org/resources/articles/727/1/Drawing-shapes-with-AS2/Page1.html

    3) Add an event listenerto each MovieClip that points to a common event handler. This listener listens for mouse clicks on that MovieClip (or MOUSE_DOWN)

    4) and use Cells.push(tempClip) to add that new MovieClip to your array so you now have one object that contains a reference to all of your cells.

    C) Create an click event handler that redraws the cell that has been clicked. Try MouseEvent.target

    You have another option to using the graphics API to draw rectangles, and that is to simply add and remove stock graphics from your Flash library. You’ll have to draw these graphics in Flash and then ‘Export for Actionscript’ to call them up.

    Hope this points you in the right direction!

    J

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.