This content has been marked as final. Show 13 replies
Very strange set up for your code. I see at least three things that are strange just in this part. One of which is probably the main problem.
First, why are you doing a clearInterval after just one call? What is the point of waiting 10 milliseconds, then doing something then clearing that interval?
Why are you doing the updateAfterEvent()? That is used to redraw the screen after the function has been called, fine for some kind of game or such, but for a loader does it really matter if the bar is drawn every 10 milliseconds or every 100? Both are tiny compared to the load time – and if they aren't then you really don't need a preloader!
Finally, and this is what is really slowing you down is that you aren't clearing your drawing. Start with a holder.clear(); and that should speed things up.
Whatever you are doing in total there are much better and cleaner ways to do it.
I know there are better ways of doing this, and im open to suggestions..this is my first try at a dynamic pre-loader.
im clearing the interval at the end of that function so that the counter clears every call made to the function.
the function it's self is the progressBar (as you can probably tell ) and i want it to re-draw to the ammount that is loaded.
second. im using updateAfterEvent() because it's re-drawing every 10mili seconds, and everytime i use drawing API it's ALOT smoother if i use updateAfterEvent()
third. I cant use clear() because that way the progressBar (the fill ) flickers, and it looks crap.
i can do this if i draw the progressBar in the timeline.. but i want the whole loader to be made at runtime.
Im open to suggestions..as i said, i KNOW there are better ways to do this, but it's my verry first attempt.
Well if you do it the way you do it then you will get the results you get. If that is what you want, then you have it.
Rethink what you are doing from the ground up. Here is what I think you want.
1. Start loading
2. Every little bit check how much is loaded
3. Draw a bar to graphic show how much is loaded
4. If not done loading go back to 2.
5. Stop checking, clear graphic, go on to rest of whatever it is you are going to do.
If this is correct, then you only need one setInterval and you only need to clear it once you have reached step 5. So whatever process you are using that keeps resetting them and all is excessive and probably part of the problem.
updateAfterEvent() can't make everything you do with the drawing API better – that isn't how it works. But my real point here is why do you need to update the bar every 10 milliseconds? That is just using too many resources for something that doesn't need them.
This is a common misconception for folks who are new to Flash. They think to make things smoother they need to do things at faster and faster speeds. They try and set the framerate at 100 or they try and do a setInterval a 1 millisecond. Flash can't handle it and chokes and things look worse that if they had lower rates. The human eye works in very mysterious ways. Remember that movies are at 24 fps and that TV is about 30.
You will need to use clear(). Because repeated drawing over and over will slow down the player too much. The flickering is probably caused by conflicting screen redraws with the updateAfterEvent() and all. I can't be sure.
People aren't computers. The point of a preloader is to show the user that their system is doing something and give them an approximation of how long it will be until it is done. Whether it is off by 100 milliseconds or not your user will not notice or care.
I understand the 5 points you mentioned, but i dont know how to implement them in AS.
i AM quite new to actionscript, just learning as i go. I've been making pre loaders for ages now, but never a dynamic loader, and i havent worked too much with drawing API, but the work i did on D API, i saw that adding updateAfterEvent() greatly improves the animation. I never set the frame rate to something silly like 100fps.
for this particular pre loader project im working on 30fps.
The way i came up with this method for a preloader, was playing with drawing API.
to re-draw lines and curves to follow the mouse. and yes i had to use clear() at the begining of the function. I know you have to.
but in this case it looked crap, so i didnt add it...I would have added it later on, if it worked right.
can you give me an example of the 5 points in your method?
or if theres an easier way, share that way instead please. =) i'll learn from that.
Write your clearInterval in the above in the above if condition.
Hope this helps
thanx fasilak, but Rothrock was right, i NEED the holder.clear() at the begining of the function.
I need a new method of doing this.
your clearInterval() would work no doubt. Thanx for the input.
Is there a reason you aren't using the MovieClipLoader class?
It has the nice onLoadProgress event. In there you would just put your bar drawing code. That way you won't have to worry about an intervals.
Also remember that if the content of your swf is lumpy – more info on some frames than others – then the bar will move in fits and starts due to the information loading in that way. So try and smooth the load.
If you do want to make your own as an exercise in learning, it wouldn't make sense for me to give you all the code, but here is a general outline:
getBytesTotal and getBytesLoaded of clipToCheck
Make sure they are bigger than 0
figure the percentage
//box drawing in clipToDraw
clear or remove clipToDraw
maybe some function to scale or fade clipToLoad
//create your empty movieclip for loading the external content into
//create your empty movieclips for the bar and such
loadMovie into the content holder
Of course that last bit should have been:
myContent.progressIntervalID=setInterval(checkProgress, 50, myContent, myProgBar);
I am using the MovieClipLoader class, and the piece of code i posted in my first post is inside the onLoadProgress function.
I didnt include it, because i know that part works, its just the slowing of the CPU that i couldnt fix, so i only posted the part that i thought is causing it.
Well this is for a site im working on, and also as a personal learning thing. I have this issue where for every new site i do, i have to try different things. while this wastes ALOT of my work time, i cant help it, but it is good learning.
Thanx for the simplyfied steps for the method, i'll give that a try. see if i can edit my code to make it work like your method.
heres my whole code, just incase you want to see it. who knows, maybe i DO have some problems in there too.
If you are using the onLoadProgress event then you don't need any interval at all. The onLoadProgress event is only called – get this! – when there is loading progress.
And the way you have this, it says, "When an there is load progress, draw an empty box, wait 10 milliseconds and then clear the box and draw a filled box representing the portion loaded, clear the Interval, and then updateAfterEvent."
I will only say this one more time. STOP using 10 millisecond intervals and updateAfterEvent(). For file loading they are not needed. If your file loads in an amount of time that is not much longer than 10 milliseconds you don't need a preloader and if it is much longer then you are only wasting cycles. Not that you even need either one if you are using onLoadProgress.
Please listen to what helpful people here tell you. If the way you were doing it was working you wouldn't need help and if you aren't willing to try what has been told to you then why are you bothering to ask?
dude, take it easy... what's your f***in problem... i aleady said im gonna try your method, and i already said that THIS IS MY FIRST TIME TRYING TO DO THIS...
if you're going to be a ******** then i dont want your help...
Yes i got it wrong... yes i did this in a weird method... I KNOW THIS...
and WTF is this???
>If you are using the onLoadProgress event then you don't need any interval at
>all. The onLoadProgress event is only called – get this! – when there is loading
where in my code do you see me using Interval for LOADING???
as for the 10milliseconds... I havent touched this code since i posted for help. it's not like i keep trying to use the same code and hope it works, no matter what you say...
IF YOU ACTUALLY READ WHAT I SAID IN MY LAST POST...I SAID THAT I ---WILL--- TRY YOUR METHOD... at NO POINT did i say that i DONT wanna try your method, and heres the code i use...
i showed you the code i had from the begining because you thought i wasnt using onLoadProgress()
now you see that i AM....but I *HAVE NOT* (<=----READ THAT) tried to implement YOUR method yet..
take it easy next time!