views:

374

answers:

4

I'm working on this Flash project and I've constructed a swf where all the assets are exported into frame 5 and the first frame contains the pre-loader. When the pre-loader is finished it jumps to frame 10 where the actual site begins. This works great.

However, in every browser I've tested so far (FF, IE, Chrome and Safari) when I place a # on the url the behaviour seems to be that the browser is downloading the entire swf first and then starts playing it with the end result that it takes a while for the swf to load (blank screen), the pre-loader kicks at a 100% and then the swf continues to the site.

I would appreciate it if anyone could confirm this behaviour and any input to shed some light on this problem.

UPDATE:

Thanks to rhtx for pointing out this annoying Flash Player behaviour. In a way I can understand why this is but it only works if you make linear movies, which I don't. Currently it means that I need to create a label for every deep link location on the first frame which is of course impossible if your path is content driven.

Is there a way to overcome this second problem?

+1  A: 

You could make a "container" swf whose only job is to load the real swf. That way it wouldn't matter if the swf on the page gets loaded completely before it runs, since it would only be a few kb in size.

asperous.us
This is how I used to do it in the "old days". Now I only like to use this approach as a last resort.
Luke
+2  A: 

I had a pretty crazy issue with writing and reading local SharedObjects when there was a # in the URL. It was painful, and I couldn't ever fully nail it down. Not the same as what you're dealing with, but I can confirm that the FP may act differently in some cases when there is a '#' in the URL.

I think what may be happening in your case is that the Flash Player is looking for an anchor, due to the '#' symbol. My guess is that it keeps looking until the entire SWF has loaded and it sees that there is no anchor anywhere in the SWF for it to match up with.

You might try something like this:

Add a new layer in your FLA on the main timeline. On the first frame, create an anchor (add keyframe, name the frame and select the 'Anchor' option when you name it). Try loading up your page again, but put the name of the anchor after the hash symbol. If it loads up as desired, then there may be something to my guess.

Hope that helps.

Ross Henderson
Spot on! However, this imposes the next problem. See my update.
Luke
Yeah. Ugh. I just did a couple of searches to see if I could learn anything about disabling DeepLinking, but didn't come up with anything. In Flex you might possibly be able to mess with this, but it doesn't look like there is an exposed way in for Flash. Least not that I saw in 20 minutes of looking. Seems like you should be able to define how to handle an 'empty' anchor, though.
Ross Henderson
@rhtx: Yeah, I was hoping for some sort of wild-card anchor but I couldn't find anything. I wonder how Flex does this. Maybe there is a way to inject some setting into the swf or maybe I it's possible to compile-in some meta data. So far, I haven't been able to find anything either. I would appreciate it if you'd find out anything relating to this issue if you'd post your findings here. Thanks!
Luke
Keith Peters has a good explanation (http://www.bit-101.com/blog/?p=946) on his blog on how to do pre-loaders with the Flex compiler (pure AS3). But it doesn't seem to apply when you're using Flash.
Luke
+1  A: 

My guess is that this bug is causing you problems. This guy has been reporting on the nature of this bug for a while.

While it sounds like you are not using flex, I would not be surprised if this bug effects pure as3 flash too.

The bug was recently closed. The solution: make a small swf preloader to load your main swf (like asperous.us) suggests.

Also see this s.o. q & a.

jedierikb
You seem to have earned yourself a bounty. Congrats!
Luke
+1  A: 

I've known about this bug a while now and use the container method to circumvent it. But I hate the container method so I sporadically search the web for solutions.

Rhtx to the rescue..

Not really as clean as it should be, but im quite happy the way it works..

The way I implemented it now is I have a frame label type anchor named "loading" on frame 1 (frame 2 is where my application lives).

Then I use a piece of javascript to load my flash site, which basically does this:

//pseudo javascript
var path = "";
function buildFlash() {
   path = location.hash.length > 1 ? location.hash.substr(1) : "";
   location.hash = "loading";
   $(document).ready(onDOMReady); //could probably directly load the swf now
}

function onDOMReady() {
   swfobject.embedSWF(... with path flashvar ...);
}

The reason this works for me is I call a function ExternalInterface("setPath", path) from flash to set the hash, which in turn also passes the path to googleanalytics.

A person visiting the url http://www.site.com/#about/ will see the url /#loading while the site loads, when the loading is finished, the flash application determines where the user should go and changes the url accordingly.

Les