Creating a Trace Bar to Track SWF Loading Progress

In summary, to display a trace bar showing the percentage of the swf that has loaded, you can use the ProgressBar component or create your own using getBytesLoaded() and getBytesTotal(). To see how much of the current swf or another swf on a different level has loaded, use the appropriate code and specify a dynamic text field to display the percentage. Preloader bars are important to inform the user of progress and to avoid a blank screen while the movie is loading. Additionally, different computers and operating systems may have compatibility issues with Flash, so it's important to check for any security settings or browser incompatibilities. When loading data from an external server, make sure to set the site's domain as allowed to avoid any restrictions.
  • #1
sid_galt
502
1
How do you display a trace bar which shows how much of the swf has loaded ?

Thank you
 
Computer science news on Phys.org
  • #3
It's pretty easy. You can use the ProgressBar component, or you can make your own. Use getBytesLoaded() and getBytesTotal().
For example to see how much of the current swf has loaded, do:
Code:
_root.onEnterFrame = function(){
   p = 100*_root.getBytesLoaded()/_root.getBytesTotal();
   _root.mytext.text = p+"% loaded";
   if(p>=100){
        // finished, do something, like go to frame 5
        delete _root.onEnterFrame;
        _root.gotoAndPlay(5);
   }
}

To see how much of an SWF, THAT YOU"RE LOADING ON ANOTHER LEVEL, SUCH AS _level0, then:
Code:
_root.onEnterFrame = function(){
   p = 100*_level0.getBytesLoaded()/_level0.getBytesTotal();
   _root.mytext.text = p+"% loaded";
   if(p>=100){
        // finished, do something, like go to frame 5
        delete _level0.onEnterFrame;
        _level0.gotoAndPlay(5);
   }
}
Where _root.mytext is a dynamic text field. This tells the user how much is loaded. As you can imagine it's easy to do some visual effects, like increment a bar.

With the ProgressBar Component, all you need is to drag an instance of the component onto the stage, select it, and in its actions type:
Code:
on(load){
	this.mode = "manual";
	this.indeterminate = false;
	this.minimum = 0;
	this.maximum = 100;
	this.onEnterFrame = function(){
		this.setProgress(_root.getBytesLoaded(), _root.getBytesTotal());
	}
}
on(complete){
	delete this.onEnterFrame;
	trace("complete");
}
 
  • #4
Thank you for the replies.

BTW, is there any way to start the swf file before it has loaded fully (mine is basically a photo reel with music so its a bit hard to compartmentalize it into different files)
 
  • #5
As long as a frame has loaded it can play, even if the whole movie has not. This is automatic if you don't have a stop() action in the first frame. On the other hand you can check if a frame has loaded, if it has you can play it, otherwise wait.
 
  • #6
Thank you for the reply.
If the the swf file loads frame by frame, then what is the need of preloader bars in flash movies?I have a couple of other problems.

1) I have made an interactive tutorial in Flash which loads text externally from a file. It contains the statistics on countries around the world. The problem is that no data is appearing for the European countries if the web page is loaded from a server even though data is coming for the other countries. The method is the same in both cases.
Another problem is that the tutorial coding is not working at all on some computers (although it is worthwhile to note that these computers also freeze frequently or are otherwise very slow) while it is working on computers which have even lower configuration than the above computers.
The tutorial is in Flash 8. All the computers have Flash player 8.

2) My flash intro is loading in a few computers but is not loading in the same computers mentioned above. The computers just show a sign of Macromedia Flash Player and that's it.

Again Thanks a lot for the help
 
  • #7
The point of preloader movies is to let the user know that things are happening. Without a loading bar you might get a blank screen while the first frames are loaded. Also most of the components you use in Flash are set to export on frame 1, this means that frame 1 sometimes is the heaviest frame and so, while it is loading, the user has no idea what is going on with the movie.

The problem is that no data is appearing for the European countries if the web page is loaded from a server even though data is coming for the other countries. The method is the same in both cases.
You have to be more specific. Is the text file in the same server as the .swf? Or from an external domain? Is data for each country loaded from the same text file, or from different ones? Is this your own server or a web host? There are some restrictions about loading data from other servers, it's not allowed unless you specifically set the site's domain as allowed.

My flash intro is loading in a few computers but is not loading in the same computers mentioned above. The computers just show a sign of Macromedia Flash Player and that's it.

What operating System and browser? Flash player is not the same for all browsers and OSs. Mac OSs have really poor flash players and there are often some browser incompatibilities. Are you sure the movie is downloading? Check you Temporary Internet Files to see if your .swf is there. Have you ruled out security settings as the cause of this?
 
Last edited:
  • #8
-Job- said:
The point of preloader movies is to let the user know that things are happening. Without a loading bar you might get a blank screen while the first frames are loaded. Also most of the components you use in Flash are set to export on frame 1, this means that frame 1 sometimes is the heaviest frame and so, while it is loading, the user has no idea what is going on with the movie.

So that means that I should set the preloader bar to play the swf file when say the first few seconds of file has loaded?

-Job- said:
You have to be more specific. Is the text file in the same server as the .swf? Or from an external domain?
Same Server

-Job- said:
Is data for each country loaded from the same text file, or from different ones?
Different files for each country

-Job- said:
Is this your own server or a web host? There are some restrictions about loading data from other servers, it's not allowed unless you specifically set the site's domain as allowed.
It's a web host. The problem is that most other countries outside of Europe are loading. Although, I have just discovered that a few countries like China are not loading either.
I have set pictures to appear dynamically along with the text too. Pictures are no problem. Only the text is.


-Job- said:
What operating System and browser?
Now that I am checking again, the problem is coming with Internet Explorer browsers which have Flash Player 8 installed.
The page loads and instead of the intro the logo of macromedia shockwave player appears for a while and then that too goes. As if the shockwave can't load the file. With Flash Player 7 in Internet Explorer, there was no problem. This problem is not there for Firefox nor for Opera.

The movie is not downloading. It's not there in the temporary internet files.

-Job- said:
Have you ruled out security settings as the cause of this?
No, but since Firefox and Opera are opening everything, I can't see how that could be the reason.
 
  • #9
Another problem is that it is the shockwave player which is attempting to load the movie not the flash player. In mozilla firefox and opera, it is the flash player and the movie loads perfectly. Should put the movie in another format or something?
 
  • #10
This is the coding in the html file that is now not running even from my home computer on IE
Code:
<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0" width="550" height="400">
    <param name="src" value="intro7.swf" />
    <embed src="intro7.swf" pluginspage="[PLAIN]http://www.macromedia.com/shockwave/download/"[/PLAIN] [Broken] width="550" height="400"></embed>
  </object>

This is the coding which is running on IE atleast from my home computer
Code:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="intro7" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="intro7.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="intro7.swf" quality="high" bgcolor="#000000" width="550" height="400" name="intro7" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

I think the first one is directing IE to the wrong codebase. Could this be the problem?
 
Last edited by a moderator:
  • #11
Allright, the loading from external txt files problem is now resolved. Turns out that although my school administrator (they are the one's who are running the site) uploaded all the files, some files were apparently left out. So that's resolved.

The only problem left is that the text files are not loading on some computers. Their configs are like 2.8 GHz P4, 768 MB Ram (freezes frequently), Windows XP and 2.8 GHz P4, 512 Ram (freezes frequently), Very Slow and AMD Sempron 2200 128 Ram, Windows XP (extremely slow).
 
  • #12
Are you 100% sure these PCs have flash 8? If you right click on the movie do you see, in the bottom entry in the menu "About Macromedia Flash Player 8..."?
Can you view other flash 8 movies, from other sites, correctly, or is it that they can't view anything at all?
 
  • #13
-Job- said:
Are you 100% sure these PCs have flash 8? If you right click on the movie do you see, in the bottom entry in the menu "About Macromedia Flash Player 8..."?
The computers all have Flash 8. However when the intro is viewed in IE, on right clicking, instead of "About Macromedia Flash Player 8", there is "About Shockwave Player". That is what made me think that there might be a problem in the way the swf file was being called into the html file.

-Job- said:
Can you view other flash 8 movies, from other sites, correctly, or is it that they can't view anything at all?

Yes, they can. The problem is only with my intro movie.

One more query: My intro movie is 1.34 MB but starts playing only when the first 800 kilobytes have been downloaded. Is there a way to start the movie when say only the first 400 kilobytes have been downloaded? (say by using the bytesLoaded function and instructing the player to play from frame 2 when the first 400,000 bytes are loaded)
 
  • #14
Allright, Everything is working now. :smile: The swf problem was as I suspected, a problem in the html coding.
And the files in the flash tutorial were not opening because the server is linux based and therefore case-sensitive. I hadn't respected case sensitivity in the naming of some txt files.

Thanks for the help everyone especially -Job-!
 
Last edited:
  • #15
So it was the HTML. Did you have Flash 8 generate the HTML via "Publish"?
 
  • #16
-Job- said:
So it was the HTML. Did you have Flash 8 generate the HTML via "Publish"?

The HTML file which worked was generated via flash with "Publish". The one that didn't work was created through Dreamweaver.
 

What is a Trace Bar?

A Trace Bar is a visual representation of the loading progress of an SWF file. It provides a way for developers to track the loading process and identify any potential issues.

Why is it important to have a Trace Bar?

Having a Trace Bar allows developers to monitor the loading progress of an SWF file, which can help identify any issues or errors that may occur during the loading process. It also provides a way to measure the performance of the file and make necessary optimizations.

How do you create a Trace Bar?

To create a Trace Bar, you will need to use ActionScript code to track the loading progress of the SWF file. This can be done by using the onEnterFrame event and the getBytesLoaded() and getBytesTotal() functions to calculate the percentage of the file that has been loaded. Then, you can use this percentage to update the visual representation of the Trace Bar.

What are the benefits of using a Trace Bar?

Aside from helping to identify and troubleshoot any issues with the loading process, a Trace Bar can also provide valuable information about the performance of the SWF file. It can help determine if the file is too large or if there are any elements that are causing delays in the loading process.

Are there any alternatives to using a Trace Bar?

Yes, there are other methods for tracking the loading progress of an SWF file, such as using the LoaderInfo class or external libraries. However, a Trace Bar is a simple and effective way to visually monitor the loading progress and is commonly used by developers.

Similar threads

  • Computing and Technology
Replies
7
Views
1K
  • Computing and Technology
Replies
5
Views
7K
  • Advanced Physics Homework Help
Replies
7
Views
808
Replies
22
Views
1K
  • Electrical Engineering
Replies
21
Views
1K
Replies
4
Views
1K
  • Special and General Relativity
3
Replies
73
Views
2K
  • Computing and Technology
Replies
2
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
986
  • Computing and Technology
Replies
30
Views
3K
Back
Top