views:

33

answers:

2

Once you load an actionscript page from scratch (in my case loading XML data from a file, initializing various other elements in a fairly time consuming way) if you navigate away from that page and then return to it, (via the browser 'back' key for example) is their a way to forego the previous initialization and just immediately bring up the previous Actionscript page in its fully initialized state.

A: 

It depends on 2 things,

  1. What you mean by "initializing other elements in a fairly time consuming way"
  2. How much data is actually being used from the XML you are loading.

If the "time consuming" stuff is doing computations based on data, or executing time based Tweens, then you can forgo them. Take a look at SharedObject, Flash's counterpart to browser cookies. You can store the results of computations and retrieve them so they don't need to be re-computed. If it is tweens (or animations) you want to "skip" then you can likewise set a key,value in the SharedObject which triggers your movie to skip certain parts and move directly to the inited state.

Depending on how much data is being used from your XML (or how big the XML is to begin with) you can do the same thing. Store the data you need in SharedObject and retrieve it instead of loading the XML again.

This all really depends on what you mean though. HTTP is a stateless protocol, as such, any page refresh will need to rebuild your application - but with the trick mentioned you should be able to get something like what you want accomplished.

sberry2A
"What you mean by "initializing other elements in a fairly time consuming way"?-The xml file contains for example the names of font library swf's that then need to be loaded.There are also the names of jpg files - those are also loaded via SWFLoader and then subsequently manipulated at startup by accessing their BitmapData for example. Some info in the XML causes setTextFormat to be called on various TextFields.So, things of that nature.
Mark
+1  A: 

Flash Player will always start up your SWF file from scratch. In most cases, navigating back will load the SWF and things like XML files from the browser's cache, and you'll be up and running faster than if you were to go there the first time. However, you're responsible for adding logic to remember the most recent state and restore it when the SWF is loaded again.

If you're using Flex, the History Manager might be useful. For AS3 without a framework, you might check out SWFAddress instead. Both of those use the browser's URL and history features to track the application state, which can allow you to navigate through the SWF as if it contains "pages" and even bookmark specific locations in the SWF. Alternatively, or maybe even simultaneously, you might also consider using Flash Player's cookie-like flash.net.SharedObject functionality to remember the the state. You lose the more granular browser navigation, but you might be able to remember more about a specific single state.

joshtynjala
I appreciate it.
Mark