473,480 Members | 4,827 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem - Simulation Speed slows down quickly (timeinterval)

2 New Member
Hi all,
the attached code works on an empty flash8-stage (size about 1024*768) (just put the code in the first frame and run). You might notice the problem: The simulation speed is slowing down quite quickly. Has anybody a solution or knows what might be the cause? I've got no idea what to do!
Thanks very much in advance!

Expand|Select|Wrap|Line Numbers
  1. var startx:Number = 100;
  2. var starty:Number = random(100)+200;
  3. moveTo(startx, starty);
  4. var positionX:Array = new Array(75);
  5. var positionY:Array = new Array(75);
  6. positionX[0]=startx;
  7. positionY[0]=starty;
  8.  
  9. for (ii:Number=1; ii<76; ii++){
  10.     moveTo(positionX[ii-1], positionY[ii-1]);
  11.     positionX[ii] = startx+(ii*10);
  12.     positionY[ii] = positionY[ii-1] + random(20)-10; 
  13.     lineStyle (5, 0x888888, 100);
  14.     lineTo(positionX[ii], positionY[ii]);
  15. }
  16.  
  17. // all 100ms new part of line
  18. timeint = setInterval(this, "drawline", 100);
  19.  
  20. var pass : Number = 1;
  21. var posx : Number = 1;
  22. function drawline() {
  23.     posx=1;
  24.     for (i:Number=1; i<76; i++) {
  25.         moveTo(positionX[posx-1], positionY[i-1]);
  26.         lineStyle (5, 0xFFFFFF, 100);
  27.         lineTo(positionX[posx], positionY[i]);
  28.         posx++;
  29.     }
  30.     for (arraypos:Number=1; arraypos<76; arraypos++) {
  31.         positionY[arraypos-1] = positionY[arraypos];
  32.     }
  33.     positionY[75]=positionY[74] + random(20)-10;
  34.     pass++;
  35.     posx=1;
  36.     for (i:Number=1; i<76; i++) {
  37.         moveTo(positionX[posx-1], positionY[i-1]);
  38.         lineStyle (5, 0x888888, 100);
  39.         lineTo(positionX[posx], positionY[i]);
  40.         posx++;
  41.     }
  42.  
  43.     //quit timeinterval after 75 loops
  44.     pass>=75?clearInterval(timeint):0;
  45.     trace(pass);
  46. }
  47.  
Aug 15 '07 #1
3 1631
xNephilimx
213 Recognized Expert New Member
Hi, strombose.
The solution is very simple, you were not clearing the stage when redrawing the lines and that was eating too much memory. You just need to add clear(); in the fisrt line of your drawline function.

Expand|Select|Wrap|Line Numbers
  1. function drawline() {
  2.     clear();
  3. //[the rest of the function here]
  4. }
  5.  
The clear method literally clears the stage of any previous drawings made by actionscript, making also release memory.

Best regards,
The_Nephilim

Hi all,
the attached code works on an empty flash8-stage (size about 1024*768) (just put the code in the first frame and run). You might notice the problem: The simulation speed is slowing down quite quickly. Has anybody a solution or knows what might be the cause? I've got no idea what to do!
Thanks very much in advance!

Expand|Select|Wrap|Line Numbers
  1. var startx:Number = 100;
  2. var starty:Number = random(100)+200;
  3. moveTo(startx, starty);
  4. var positionX:Array = new Array(75);
  5. var positionY:Array = new Array(75);
  6. positionX[0]=startx;
  7. positionY[0]=starty;
  8.  
  9. for (ii:Number=1; ii<76; ii++){
  10.     moveTo(positionX[ii-1], positionY[ii-1]);
  11.     positionX[ii] = startx+(ii*10);
  12.     positionY[ii] = positionY[ii-1] + random(20)-10; 
  13.     lineStyle (5, 0x888888, 100);
  14.     lineTo(positionX[ii], positionY[ii]);
  15. }
  16.  
  17. // all 100ms new part of line
  18. timeint = setInterval(this, "drawline", 100);
  19.  
  20. var pass : Number = 1;
  21. var posx : Number = 1;
  22. function drawline() {
  23.     posx=1;
  24.     for (i:Number=1; i<76; i++) {
  25.         moveTo(positionX[posx-1], positionY[i-1]);
  26.         lineStyle (5, 0xFFFFFF, 100);
  27.         lineTo(positionX[posx], positionY[i]);
  28.         posx++;
  29.     }
  30.     for (arraypos:Number=1; arraypos<76; arraypos++) {
  31.         positionY[arraypos-1] = positionY[arraypos];
  32.     }
  33.     positionY[75]=positionY[74] + random(20)-10;
  34.     pass++;
  35.     posx=1;
  36.     for (i:Number=1; i<76; i++) {
  37.         moveTo(positionX[posx-1], positionY[i-1]);
  38.         lineStyle (5, 0x888888, 100);
  39.         lineTo(positionX[posx], positionY[i]);
  40.         posx++;
  41.     }
  42.  
  43.     //quit timeinterval after 75 loops
  44.     pass>=75?clearInterval(timeint):0;
  45.     trace(pass);
  46. }
  47.  
Aug 16 '07 #2
strombose
2 New Member
Thanks a lot for your help! It works.
Aug 16 '07 #3
xNephilimx
213 Recognized Expert New Member
Thanks a lot for your help! It works.
You're welcome.
Good luck!

Best regards,
The_Nephilim
Aug 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2937
by: Rob Ristroph | last post by:
I have tried out PHP 5 for the first time (with assistance from this group -- thanks!). The people I was working with have a site that uses lots of php objects. They are having problems with...
16
2458
by: lkrubner | last post by:
Are there any benchmarks on how much an extra, unneeded VARCHAR, CHAR, INT, BIGINT, TEXT or MEDIUMTEXT slows down a database call with MySql? PostGre info would also be useful. I'm trying to...
11
1808
by: Jonny | last post by:
Netscape 7.02 is giving me a headache with a downloaded snow script. Starting with a blank page, I inserted the script and checked it in IE 6 and Netscape 7.02. Everything worked and looked fine. A...
2
3488
by: zheenma | last post by:
There is a program that speed up your typing and avoid spelling errors. My friends use it ,their averege is more than 100 wpm. You can download it from www.wamasoft.com. And It has a library for...
6
2270
by: Larry R Harrison Jr | last post by:
I have a database I'm designing in Access 97. I have a custom field in a query which looks in {Table of Documents} and shows them all. It then needs a "latest revision number," stored in another...
5
3401
by: WoodenSword | last post by:
Hi, I am trying to read a huge text file (2GB) using StreamReader. I do this: Read a line (readline()) I process the line a bit (split it with delimeter and change fields a bit) execute...
4
4261
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
5
1618
by: Pitaridis Aristotelis | last post by:
I have a large file which has to be downloaded from a user using the Internet Explorer. The problem is that when someone downloads this file, the server slows down and the other users can not see...
8
2081
by: Surya Dutt | last post by:
Hello, Did someone happen to come accross and algorithm or a C++ program that simulates the Smith Collge Diploma problem? "At Smith College, the graduation exercises traditionally proceed as...
0
7040
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6905
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6908
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
561
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.