PDA

View Full Version : My preloader works locally, but not on a server



MFoller
March 7th, 2009, 04:57 PM
Hi everyone, I'm new here and here goes with my first post:

I'm working on a website (www.fworks.dk (http://www.fworks.dk) - don't think the flash file can be seen in FF yet) and I want to load an swf-file with some illustrations and such. As this could get a little big, I have made another swf-file which shows a preloader and loads the first swf-file. The preloader works perfectly when tested in Flash CS3, but when uploaded to and tried on my webhost's server, the preloader doesn't load anything. Instead it of the load-percentage it just writes "NaN".

You can finde the as3-code down below. The preloader-swf and the swf to be loaded are located in the same folder. Both are as3.

I really hope one of you guros can help me. Thanks a lot in advance.

This is the code from my as-class file:


package classes{

// Imports necessary classes
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.*;
import flash.display.Loader;
import flash.display.DisplayObject;

public class LoadBar extends MovieClip {
public function LoadBar() {
// Code starts here

// Defines the initial states of the bar and border
loadBar_mc.scaleX = 0;
loadBorder_mc.visible = false;

// Creates a loader and defines what to load
var loader = new Loader();
loader.load(new URLRequest("done.swf"));
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onCompleteHandler);
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, progressHandler);
addChild(loader);

// Defines what happens when the file has been loaded
function onCompleteHandler(e:Event):void {
loadBar_mc.visible = false;
loadBorder_mc.visible = false;
loadText_txt.visible = false;
}

// Defines what happens while the file is being loaded
function progressHandler(e:ProgressEvent):void {
var percent = (e.bytesLoaded / e.bytesTotal);
loader.visible = true;
loadBar_mc.scaleX = percent;
loadBorder_mc.visible = true;
loadBar_mc.visible = true;
loadText_txt.visible = true;
loadText_txt.text = "Loading environment " + (Math.round(percent * 100)) + "%";
}

// Code ends here
}
}
}

idahotallpaul
March 9th, 2009, 05:41 AM
I just ran into a similar situation. I had two files - preloader.swf and content.swf. Everything worked well locally, but when I uploaded it to the server things broke. The problem for me was that the directory structure was different locally than remotely. I had to store the swfs in /images/site/flash. From default.aspx, I could get the preloader.swf to load, but preloader.swf couldn't find content.swf. In Safari, I looked at the activity monitor and preloader.swf was trying to load the file from the root directory - it was treating / as the place to look for the swf, not /images/site/flash.

The solution was to add a parameter to my embedding code for the base url. I'm using swfobject, so I had to embed it like this:


<script src="js/swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
var flashvars = {};
var params = {
menu: "false",
scale: "noScale",
base: "images/site/flash/"
};
swfobject.embedSWF("/images/site/flash/home_banner_030909.swf", "altContent", "699", "268", "9.0.0", "/images/site/flash/expressInstall.swf", flashvars, params);
</script>
<div id="altContent">
<h1>Main</h1>
<p>Alternative content</p>
<p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
</div>

Hope that helps!

MFoller
March 10th, 2009, 04:04 PM
Thank you SO much idahot, I finally solved the issue thanks to your suggestion. I couldn't quite get the swfobject to work, so I did a little workaround by simply linking to the specific location of the swf-file (i.e. http://www.fworks.dk/flash/... etc.) instead of the relative location. That works just fine, and it saves me a lot of code ;)

By the way, I had no idea that Safari had that Activity Monitor tool. It is incredibly helpful! I think I might just start to do my site-testings in Safari from now on.

A friend of mine once had a similar problem, when trying to use the relative paths of some image files from an xml-file in Flash. I find it odd though that Adobe let this kind of path-error into their programming. But well, I guess thing like these just happen from time to time.

Thanks again for the help, you really saved my project! :)