This is a discussion on "any other way of writing this crashy code?" within the Flash & Multimedia Forum section. This forum, and the thread "any other way of writing this crashy code? are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
any other way of writing this crashy code?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
any other way of writing this crashy code?
I wrote a simple preloader which will gauge how much of the flash file is already loaded. ( related to e question I asked about whether flash can keep images in browser cache ). Well, I wrote the below code and the computer crashed. :sad: Is there any other way of writing the code, but ensure that the code is carried out in a movieclip? ( because at the main timeline, I am running an animation so I cannot put a stop(); action there ).
while ((loadedbytes/totalbytes)!=1) { height = int(Math.round((loadedbytes/totalbytes)*10)); } this._height=height Note : on my main timeline first frame, I had these code. loadedbytes=getBytesLoaded(); totalbytes=getBytesTotal(); Also, the this._height refers to the movie clip's height. I wanted to create a vertical bar not a typical horizontal bar most bar preloaders utilise. :razz: |
|
|
|
#2
|
|||
|
|||
|
Ok, the while loop you are trying to perform will use up 100% of the CPU.
It also doens't take into account slight inconsistencies in how flash checks the filesize of 1) the file it's loading and 2) how much it's loaded. Flash can tell exactly how much it's loaded, but the file size it receives is always a slight approximation. Therefore you only need one to be slightly less than the other, and your code falls over. Due to the approximation and the way bits and bytes work, totalbytes will only ever be less than loaded bytes (once the file is fully loaded). However in most new versions of flash and on most computers == will be fine - This code is simply a fail safe. The best way to do this is: loadedbytes >= totalbytes That way, as soon as loaded is the same or more than totalbytes, you know loading is complete. Now you may be asking yourself - How can people in most basic programming languages, such as C, or C++ do loops without using 100% of the CPU? In C, the sleep command is used, to tell the computer to pause for x amount of milliseconds before running the script again. In Flash, we can't do that - So you HAVE to spread your code onto more than one frame and take advantage of the delay inbetween. |
|
#3
|
|||
|
|||
|
thanks for helping! I thought my code was simple so it wouldn't use too much processor cycles.
|
![]() |
| Tags |
| other, writing, crashy, code |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Writing a Book? | Jack Franklin | Webforumz Cafe | 16 | Feb 27th, 2008 08:26 |
| live search code and styleswitcher code | hebel | JavaScript Forum | 0 | May 12th, 2007 06:16 |
| Can somebody give me the code to hide the source code? | renren | JavaScript Forum | 7 | Mar 7th, 2006 12:27 |
| Over-writing content if name is the same | lobster1983 | PHP Forum | 1 | Oct 1st, 2005 23:12 |
| Access DB writing | matteobo | Databases | 1 | Feb 9th, 2005 05:46 |