Class Index | File Index

Classes


Namespace R.engine.Script

A static class which is used to load new JavaScript into the browser. Methods are also provided to use AJAX to get text and JSON data on-the-fly, load stylesheets, and process script callbacks from a loader queue.
Defined in: engine.script.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Field Summary
Field Attributes Field Name and Description
<static>  
R.engine.Script.SCRIPT_LOADED
Status message when a script is successfully loaded
<static>  
R.engine.Script.SCRIPT_NOT_FOUND
Status message when a script is not found
Method Summary
Method Attributes Method Name and Description
<static>  
R.engine.Script.ajaxLoad(path, data, callback)
Low-level method to call jQuery to use AJAX to load a file asynchronously.
<static>  
R.engine.Script.clearScriptCache()
Clears the script name cache.
<static>  
R.engine.Script.dumpScripts()
Output the list of scripts loaded by the Engine to the console.
<static>  
R.engine.Script.include(scriptURL)
Include a script file.
<static>  
R.engine.Script.load(scriptSource)
Load a script relative to the engine path.
<static>  
R.engine.Script.loadGame(gameSource, gameObjectName, gameDisplayName)
Loads a game's script.
<static>  
R.engine.Script.loadJSON(path, data, callback)
Load text from the specified path and parse it as JSON.
<static>  
R.engine.Script.loadScript(scriptPath)
Queue a script to load from the server and append it to the head element of the browser.
<static>  
R.engine.Script.loadStylesheet(stylesheetPath, relative, noInject)
Load a stylesheet and append it to the document.
<static>  
R.engine.Script.loadText(path, data, callback)
Load text from the specified path.
<static>  
R.engine.Script.pauseQueue(state)
You can pause the queue from a callback function, then unpause it to continue processing queued scripts.
<static>  
R.engine.Script.setQueueCallback(cb)
Put a callback into the script queue so that when a certain number of files has been loaded, we can call a method.
Namespace Detail
R.engine.Script
Field Detail
<static> R.engine.Script.SCRIPT_LOADED
Status message when a script is successfully loaded

<static> R.engine.Script.SCRIPT_NOT_FOUND
Status message when a script is not found
Method Detail
<static> R.engine.Script.ajaxLoad(path, data, callback)
Low-level method to call jQuery to use AJAX to load a file asynchronously. If a failure (such as a 404) occurs, it shouldn't fail silently.
Parameters:
path
{String} The url to load
data
{Object} Optional arguments to pass to server
callback
{Function} The callback method

<static> R.engine.Script.clearScriptCache()
Clears the script name cache. Allows scripts to be loaded again. Use this method with caution, as it is not recommended to load a script if the object is in use. May cause unexpected results.

<static> R.engine.Script.dumpScripts()
Output the list of scripts loaded by the Engine to the console.

<static> R.engine.Script.include(scriptURL)
Include a script file.
Parameters:
scriptURL
{String} The URL of the script file

<static> R.engine.Script.load(scriptSource)
Load a script relative to the engine path. A simple helper method which calls #loadScript and prepends the engine path to the supplied script source.
Parameters:
scriptSource
{String} A URL to load that is relative to the engine path.

<static> R.engine.Script.loadGame(gameSource, gameObjectName, gameDisplayName)
Loads a game's script. This will wait until the specified gameObjectName is available before running it. Doing so will ensure that all dependencies have been resolved before starting a game. Also creates the default rendering context for the engine.

All games should execute this method to start their processing, rather than using the script loading mechanism for engine or game scripts. This is used for the main game script only. Normally it would appear in the game's "index" file.

 <script type="text/javascript">
    // Load the game script
    Engine.loadGame('game.js','Spaceroids');
 </script>

The game can provide configuration files which will be loaded and passed to the game's setup() method. The name of the configuration file is the game as the game's main JavaScript file. If your JavaScript file is "game.js", the format for the config files are:

Examples: game_mobilesafari.config, game_mobilesafari_ipad.config
Parameters:
gameSource
{String} The URL of the game script.
gameObjectName
{String} The string name of the game object to execute. When the framework if ready, the startup() method of this object will be called.
gameDisplayName Optional
{String} An optional string to display in the loading dialog

<static> R.engine.Script.loadJSON(path, data, callback)
Load text from the specified path and parse it as JSON.
Parameters:
path
{String} The url to load
data
{Object} Optional arguments to pass to server
callback
{Function} The callback method which is passed the JSON object and status code (a number) of the request.

<static> R.engine.Script.loadScript(scriptPath)
Queue a script to load from the server and append it to the head element of the browser. Script names are cached so they will not be loaded again. Each script in the queue is processed synchronously.
Parameters:
scriptPath
{String} The URL of a script to load.

<static> R.engine.Script.loadStylesheet(stylesheetPath, relative, noInject)
Load a stylesheet and append it to the document. Allows for scripts to specify additional stylesheets that can be loaded as needed. Additionally, you can use thise method to inject the engine path into the css being loaded. Using the variable $<enginePath>, you can load css relative to the engine's path. For example:
   .foo {
      background: url('$<enginePath>/myGame/images/bar.png') no-repeat 50% 50%;
   }
Parameters:
stylesheetPath
{String} Path to the stylesheet, relative to the engine path.
relative
{Boolean} Relative to the current path, or from the engine path
noInject
{Boolean} true to bypass engine path injection and use a <link /> tag to load the styles instead.

<static> R.engine.Script.loadText(path, data, callback)
Load text from the specified path.
Parameters:
path
{String} The url to load
data
{Object} Optional arguments to pass to server
callback
{Function} The callback method which is passed the text and status code (a number) of the request.

<static> R.engine.Script.pauseQueue(state)
You can pause the queue from a callback function, then unpause it to continue processing queued scripts. This will allow you to wait for an event to occur before continuing to to load scripts.
Parameters:
state
{Boolean} true to put the queue processor in a paused state.

<static> R.engine.Script.setQueueCallback(cb)
Put a callback into the script queue so that when a certain number of files has been loaded, we can call a method. Allows for functionality to start with incremental loading.
Parameters:
cb
{Function} A callback to execute

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Mar 18 2013 16:09:18 GMT-0400 (EDT)