any other way of writing this crashy code?

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.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Flash & Multimedia Forum

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Jun 4th, 2004, 04:33
Reputable Member
Join Date: Aug 2003
Location: Singapore
Posts: 321
Thanks: 0
Thanked 0 Times in 0 Posts
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:
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Jun 4th, 2004, 07:55
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Jun 4th, 2004, 11:20
Reputable Member
Join Date: Aug 2003
Location: Singapore
Posts: 321
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for helping! I thought my code was simple so it wouldn't use too much processor cycles.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
other, writing, crashy, code

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 23:22.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42