A Generic Loading Movie

In addtion to preloading specific assets, entire shockwave movies can be preloaded. In this example, we will create a generic preloader movie. To be generic and usable without having to create a separate loading movie for each shockwave movie to be preloaded, we need to be able to tell the loading movie what file to preload (we could just hard-wire this information into the preloader movie, but this would mean we would have to publish a different preloader for each movie).

There are a couple of ways we could tell the preloader what to load. For instance, the loading movie could use getNetText to ask the server what to load. However, the simplest method is to specify the target movie using the sw1 parameter of the OBJECT and EMBED tag used to embed the movie. For example, if we want to load a shockwave movie called "Filename.dcr", we could specify this file using the following HTML (with many of the additional parameters trimmed):

<object ... width=400 height=300> 

<param name= src  value="/assets/dcr/loader.dcr"> 

<param name="sw1" value="/assets/dcr/Filename.dcr"> 


<embed ...


	 sw1="/assets/dcr/Filename.dcr" >



When the preload movie starts, we can read the sw1 parameter using the externalParamValue lingo function. Once we know the URL of the movie to load, we can start a preload.

Here's an example of a behaviour that reads the SW1 parameter. If it discovers the name of the file to preload, it starts a preload operation (using the Net.Op script discussed earlier). Once the preload is complete, it then uses goToNetMovie to jump to the preloaded movie.

property myProgressBar

on beginSprite (me)



on exitframe

  go to the frame


on ReadParams (me) 

  MovieToLoad = EMPTY

  mx = externalParamcount() 

  if mx > 1 then   

    repeat with i = 1 to mx

      n = externalParamName(i)

      v = externalParamValue(i)

      if n = "sw1" then

        MovieToLoad = v

        exit repeat

      end if

    end repeat

  end if 


  if MovieToLoad.length > 0 then 


    URLToLoad = "http://www.lingoworkshop.com/dcr/"&MovieToLoad

    canvas = (the stage).image

    rct = rect(10,10,110,22)

    myProgressBar = script("Widget.ProgressBar").new()

    myProgressBar.initialise(canvas, rct)

    netOp = script("NetOp.Preloader").new(URLToLoad)



    alert "Error retrieving movieToLoad parameter"


  end if


on PreloadFinished (me, netOp, err)


  myProgressBar = VOID

  if err <> 0 then 

    d = netOp.GetErrorDescription(err)

    alert "Error preloading movie " & return & return & d



    theUrl = netOp.url   


    id = goToNetMovie(theUrl)

  end if


on PreloadStatusUpdate (me, netOp, status)

  if myProgressBar.ilk = #Instance then 

    if status[#state] = "InProgress" then 


    else myProgressBar.ShowWorking()

  end if


Source Movie (Director MX) available. (this is the same Loader movie used throughout the Lingoworkshop).

Note - If you are using Director MX2004, you will need to change the lingo that creates a timeout object in the "NetOp.Preloader" script to the new syntax:

-- DMX 8.5/MX syntax

aTimerObj = timeout(me.string).new(10, #Timer_CheckProgress, me)

-- DMX 2004 syntax

aTimerObj = timeout().new(me.string, 10, #Timer_CheckProgress, me)
First published 04/07/2005