Code:
package {
stop();
import flash.utils.clearInterval;
import flash.utils.setInterval;
loadingBar.scaleX = 1;
var loadingCall:Number = setInterval(preloadSite, 50);
function preloadSite():void {
public var siteLoaded:Number = _root.getBytesLoaded();
public var siteTotal:Number = _root.getBytesTotal();
public var percentage:Number = Math.round(siteLoaded/siteTotal*100);
loadingBar.scaleX = percentage;
percentClip.percentDisplay.text = percentage + "%";
percentClip.x = loadingBar.x + loadingBar.width;
bytesDisplay.text = "loaded " + siteLoaded + " of " + siteTotal + " bytes";
if (siteLoaded >= siteTotal) {
clearInterval(loadingCall);
gotoAndStop(5);
}
}
}
There a a few things inherently wrong with this conversion, so lets look at the error messages:
Code:
1037: Packages cannot be nested
This error suggests that the code is either in the actions layer in a movie timeline, which makes it already part of the package the doc class is part of, or the code is internal to another package.
Typically the package is used like a container for a class or a group of classes, like this:
Code:
package
{
import flash.display.Sprite;
import flash.text.TextField;
/*
* This is a very simple class that only does one thing:
* It creates a textfield and adds it to the display list.
* The purpose of this class is to show the required imports (above)
* and procedure needed (below) to create a field using OOD in AS3.
* It also provides a base class for other classes.
*/
public class TextExample extends Sprite
{
public function TextExample ()
{
var field:TextField=new TextField ;
addChild (field);
}
}
}
It is very likely that the converter that was used was designed around converting AS2 classes to AS3.
the second error:
Code:
1114: The public attribute can only be used inside a package
really just reiterates the first. The package key word was ignored by the compiler, and then the use of 'public' for a variable, which is used for determining the accessibility of a variable outside of a particular class, threw the error.
If you are using this code inside a fla on the actions layer of the timeline, then remove the package and its braces, then remove the word public from the variables used.
I would suggest using a doc class similar to the following:
Code:
package
{
import flash.display.*;
import flash.text.*;
import flash.net.URLRequest;
import flash.events.*;
/*
* This class creates and utilizes listeners for multiple
* download progress related events when loading an image
*/
public class LoaderExample extends Sprite
{
public function LoaderExample ()
{
//Create the loader and add it to the display list
var loader:Loader=new Loader ;
addChild (loader);
//Add the event handlers to check for progress
loader.contentLoaderInfo.addEventListener (Event.OPEN,handleOpen);
loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS,handleProgress);
loader.contentLoaderInfo.addEventListener (Event.COMPLETE,handleComplete);
//Load the external image
loader.load (new URLRequest("image.jpg"));
}
//handler for the open
private function handleOpen (event:Event):void
{
trace ("open");
}
//handler for the progress
private function handleProgress (event:ProgressEvent):void
{
var percent:Number=event.bytesLoaded / event.bytesTotal * 100;
trace ("progress, percent = " + percent);
}
//handler for the completion
private function handleComplete (event:Event):void
{
trace ("complete");
}
}
}
Granted this example only loads an image, but it may help you out. If you are using Flash CS3 you would save it as LoaderExample.as in the same folder as the .fla and then in the property inspector of the fla with nothing selected enter LoaderExample into the document class field.
I hope I did not give you TMFI on this. If you want more information on custom classes in AS3 check out Actionscript 3.0 Cookbook Ch 2
Good Luck!