Kiwi.Files.DataFile Class
DataFile which contains settings, loading, and processing details for Data files to be used. There is no tag loader support for this method of loading.
Constructor
Kiwi.Files.DataFile
-
game
-
params
Parameters:
-
game
Kiwi.GameThe game that this file is for
-
params
ObjectOptions for this file.
-
key
StringUser defined name for this file. This would be how the user would access it in the file store.
-
url
StringLocation of the file to be loaded.
-
[metadata={}]
Object optionalAny metadata to be associated with the file.
-
[state=null]
Kiwi.State optionalThe state that this file belongs to. Used for defining global assets vs local assets.
-
[fileStore=null]
Kiwi.Files.FileStore optionalThe filestore that this file should be save in automatically when loaded.
-
[type=UNKNOWN]
Number optionalThe type of file this is.
-
[tags]
Array optionalAny tags to be associated with this file.
-
[parse]
Boolean optionalIf the response should be parsed after the file is loaded. Only used with JSON and XML types of Data files.
-
Returns:
Item Index
Methods
- _assignFileDetails
- _getXhrHeaderInfo
- _load
- _parseParamsOld
- _start
- _stop
- addTag
- destroy
- getFileDetails deprecated
- hasTag
- load
- loadDetails
- loadError
- loadProgress
- loadSuccess
- objType
- parseParams
- parseXML
- processJSON
- processXhr
- removeTag
- xhrHeadOnError
- xhrHeadOnLoad
- xhrHeadRequest
- xhrLoader
- xhrOnLoad
- xhrOnProgress
Properties
- _loadInParallel
- _tags
- _xhr
- attemptCounter
- buffer deprecated
- bytesLoaded
- bytesTotal
- complete
- data
- dataType
- detailsReceived
- duration
- error
- ETag
- extension
- fileName deprecated
- filePath deprecated
- fileSize deprecated
- fileStore
- fileType deprecated
- fileURL deprecated
- game
- hasError
- hasTimedOut deprecated
- headCompleteCallback
- headCompleteContext
- isAudio
- isData
- isTexture
- key
- lastModified
- lastProgress
- loading
- loadInParallel
- maxLoadAttempts
- name
- onComplete
- onCompleteCallback deprecated
- onProgress
- onProgressCallback deprecated
- ownerState
- parse
- path
- percentLoaded
- readyState deprecated
- size
- status deprecated
- statusText deprecated
- success
- timedOut deprecated
- timeFinished
- timeOutDelay
- timeStarted
- type
- URL
- useTagLoader
Methods
_assignFileDetails
-
url
Gets the file details from the URL passed. Name, extension, and path are extracted.
Parameters:
-
url
String
_getXhrHeaderInfo
()
private
Retrieves the HEAD information from the XHR. This method is used for both 'load' and 'loadDetails' methods.
_load
()
protected
Increments the counter, and calls the approprate loading method.
_parseParamsOld
-
dataType
-
path
-
[name='']
-
[saveToFileStore=true]
-
[storeAsGlobal=true]
Assigns properties and variables for the constructor as in pre 1.2 Kiwi versions.
Parameters:
-
dataType
NumberThe type of file that is being loaded. For this you can use the STATIC properties that are located on this class for quick code completion.
-
path
StringThe location of the file that is to be loaded.
-
[name='']
String optionalA name for the file. If no name is specified then the files name will be used.
-
[saveToFileStore=true]
Boolean optionalIf the file should be saved on the file store or not.
-
[storeAsGlobal=true]
Boolean optionalIf this file should be stored as a global file, or if it should be destroyed when this state gets switched out.
_start
()
private
Is executed when this file starts loading. Gets the time and resets properties used in file loading.
_stop
()
private
Is executed when this file stops loading.
addTag
-
tag
Adds a new tag to this file.
Parameters:
-
tag
StringThe tag that you would like to add
destroy
()
public
Destroys all external object references on this object.
getFileDetails
-
[callback=null]
-
[maxLoadAttempts=1]
-
[timeout=this.timeOutDelay]
Attempts to make the file send a XHR HEAD request to get information about the file that is going to be downloaded. This is particularly useful when you are wanting to check how large a file is before loading all of the content.
Parameters:
-
[callback=null]
Any optionalThe callback to send this FileInfo object to.
-
[maxLoadAttempts=1]
Number optionalThe maximum amount of load attempts. Only set this if it is different from the default.
-
[timeout=this.timeOutDelay]
Number optionalThe timeout delay. By default this is the same as the timeout delay property set on this file.
hasTag
-
tag
Checks to see if a tag that is passed exists on this file. Returns a boolean that is used as a indication of the results. True means that the tag exists on this file.
Parameters:
-
tag
StringThe tag you are checking to see exists.
Returns:
If the tag does exist on this file or not.
load
()
public
Starts the loading process for this file. Passing parameters to this method has been deprecated and only exists for backwards compatibility.
loadDetails
-
[callback]
-
[context]
Makes a XHR HEAD request to get information about the file that is going to be downloaded. This is particularly useful when you are wanting to check how large a file is before loading all of the content.
Parameters:
-
[callback]
Any optional -
[context]
Any optional
Returns:
If the request was made
loadError
-
error
Executed when the loading process fails. This could be for any reason
Parameters:
-
error
AnyThe event / reason for the file to not be loaded.
loadProgress
()
protected
Should be called by the loading method. Dispatches the 'onProgress' callback.
loadSuccess
()
protected
Called by the loading methods when the file has been loaded and successfully processed. Dispatches the 'onComplete' callback and sets the appropriate properties.
objType
()
String
public
Returns the type of this object
Returns:
"DataFile"
parseParams
-
[params]
Sets properties for this instance based on an object literal passed. Used when the class is being created.
Parameters:
-
[params]
Object optional-
[metadata]
optional{Object} Any metadata to be associated with the file.
-
[state=null]
Kiwi.State optionalThe state that this file belongs to. Used for defining global assets vs local assets.
-
[fileStore=null]
Kiwi.Files.FileStore optionalThe filestore that this file should be save in automatically when loaded.
-
[type=UNKNOWN]
Number optionalThe type of file this is.
-
[tags]
Array optionalAny tags to be associated with this file.
-
[parse]
Boolean optionalIf the response should be parsed after the file is loaded.
-
parseXML
-
data
Attempts to parse a string which is assumed to be XML. Called when 'parse' is set to true. If valid 'loadSuccess' is called, otherwise 'loadError' is executed
Parameters:
-
data
String
processJSON
-
data
Attempts to parse a string which is assumed to be JSON. Called when 'parse' is set to true. If valid 'loadSuccess' is called, otherwise 'loadError' is executed
Parameters:
-
data
String
processXhr
-
response
Handles decoding the arraybuffer into audio data.
Parameters:
-
response
Object
removeTag
-
tag
Removes a tag from this file.
Parameters:
-
tag
StringThe tag that is to be removed.
xhrHeadOnError
-
event
Executed when a xhr head request fails
Parameters:
-
event
Any
xhrHeadOnLoad
-
event
Executed when a XHR head request has loaded. Checks that the status of the request is 200 before classifying it as a success.
Parameters:
-
event
Any
xhrHeadRequest
()
private
Sets up a XMLHttpRequest object and sends a HEAD request.
xhrLoader
-
[method="GET"]
-
[responseType="text"]
-
[timeoutDelay]
Sets up a XHR loader based on the properties of this file and parameters passed.
Parameters:
-
[method="GET"]
String optionalThe method this request should be made in.
-
[responseType="text"]
String optionalThe type of response we are expecting.
-
[timeoutDelay]
Number optional
xhrOnLoad
-
event
Fired when the file has been loaded. Checks that the response contains information before marking it as a success.
Parameters:
-
event
Any
xhrOnProgress
-
event
Progress event fired whilst the file is loading via XHR.
Parameters:
-
event
Any
Properties
_loadInParallel
Boolean
private
Indicates if this file can be loaded in parallel to other files. This is usually only used files are using the tag loaders and not XHR.
Default: false
_xhr
XMLHttpRequest
protected
The XMLHttpRequest object. This only has a value if the xhr method of load is being used, otherwise this is null.
attemptCounter
Number
protected
The number of attempts at loading there have currently been at loading the file. This is only used with XHR methods of loading.
buffer
Any
deprecated
public
The response that is given by the XHR loader when loading is complete.
bytesLoaded
Number
public
The number of bytes that have currently been loaded. Useful when wanting to know exactly how much data has been transferred. Only has a value when using the XHR method of loading.
Default: 0
bytesTotal
Number
public
The total number of bytes that the file consists off. Only has a value when using the XHR method of loading or you are getting the file details before hand.
Default: 0
complete
Boolean
public
Indicates if the file has attempted to load. This is regardless of whether it was a success or not.
Default: false
data
Any
public
A dictionary, stores any information relating to this file. Used when loading images that are to be used as a spritesheet or texture atlas.
dataType
String
public
Holds the type of data that is being loaded. This should be used with the STATIC properties that hold the various datatypes that can be loaded.
detailsReceived
Boolean
public
An indication of whether this files information has been retrieved or not.
Default: false
duration
Number
public
The duration or how long it took to load the file. In milliseconds.
Default: 0
error
Any
public
Holds the error (if there was one) when loading the file.
ETag
String
public
The Entity Tag that is assigned to the file. O Only has a value when either using the XHR loader OR when requesting the file details.
extension
String
public
The extension of the file that is being loaded. This is based upon what the file path that the developer specifies.
fileName
String
deprecated
public
The name of the file being loaded.
filePath
String
deprecated
public
The location of where the file is placed without the file itself (So without the files name). Example: If the file you are load is located at 'images/awesomeImage.png' then the filepath will be 'images/'
fileSize
Number
deprecated
public
The size of the file that was/is being loaded. Only has a value when the file was loaded by the XHR method OR you request the file information before hand using 'getFileDetails'.
fileStore
Kiwi.Files.FileStore
public
The filestore this file should be added to when it has loaded. This can be replaced with a custom one if wanted.
fileType
String
deprecated
public
The type of file that is being loaded. Is only ever given a value when used with the XHR method of loading OR if you use 'getFileDetails' before hand. The value is based off of the 'Content-Type' of the XHR's response header returns.
fileURL
String
deprecated
public
The full filepath including the file itself.
hasError
Boolean
public
If file loading failed or encountered an error and so was not laoded
Default: false
hasTimedOut
Boolean
deprecated
public
If this file has timeout when it was loading.
Default: false
headCompleteCallback
Any
private
The callback method to be executed when the file details have been retrieved.
headCompleteContext
Any
private
The context the 'headCompleteCallback' should be executed in.. The callback is the following arguments.
- If the details were recieved
isAudio
Boolean
public
An indication of if this file is a piece of audio. This is READ ONLY.
isData
Boolean
public
An indication of if this file is data. This is READ ONLY.
isTexture
Boolean
public
An indication of if this file is texture. This is READ ONLY.
key
String
public
The 'key' is the user defined name and the users way of accessing this file once loaded.
lastModified
String
public
The last date/time that this file was last modified. Only has a value when using the XHR method of loading OR when requesting the file details.
Default: ''
lastProgress
Number
public
The time at which progress in loading the file was last occurred. Only contains a value when using XHR methods of loading.
loading
Boolean
public
Indication if the file is currently being loaded or not.
loadInParallel
Boolean
private
READ ONLY: Indicates if this file can be loaded in parallel to other files. This is usually only used files are using the tag loaders and not XHR.
Default: false
maxLoadAttempts
Number
public
The maximum attempts at loading the file that there is allowed.
Default: 2
name
String
public
The name of the file being loaded.
onCompleteCallback
Any
deprecated
public
A method that is to be executed when this file has finished loading.
Default: null
onProgress
Kiwi.Signal
public
Signal which dispatches events when the file is loading. Not guarenteed to dispatch events as it depends on the method of loading being performed
onProgressCallback
Any
deprecated
public
A method that is to be executed while this file is loading.
Default: null
parse
Boolean
public
If the response should be parsed (using the appropriate method) after loading. Example: If set to the true and the dataType set is json, then the response will be sent through a JSON.parse call.
Default: false
path
String
public
The location of where the file is placed without the file itself (So without the files name). Example: If the file you are load is located at 'images/awesomeImage.png' then the filepath will be 'images/'
percentLoaded
Number
public
The amount of percent loaded the file is. This is out of 100.
readyState
Number
deprecated
public
The ready state of the XHR loader whilst loading.
Default: 0
size
Number
public
The size of the file that was/is being loaded. Only has a value when the file was loaded by the XHR method OR you request the file information beforehand using 'loadDetails'.
Default: 0
status
Number
deprecated
public
The status of this file that is being loaded. Only used/has a value when the file was/is being loaded by the XHR method.
Default: 0
statusText
String
deprecated
public
The status piece of text that the XHR returns.
Default: ''
success
Boolean
public
If loading was successful or not.
timedOut
Number
deprecated
public
If the file timed out or not.
Default: 0
timeFinished
Number
public
The time at which the load finished.
Default: 0
timeOutDelay
Number
public
The number of milliseconds that the XHR should wait before timing out. Set this to NULL if you want it to not timeout.
Default changed in v1.3.1 to null
Default: null
timeStarted
Number
public
The time at which the loading started.
Default: 0
type
String
public
The type of file that is being loaded. Is only ever given a value when used with the XHR method of loading OR if you use 'loadDetails' before hand. The value is based off of the 'Content-Type' of the XHR's response header returns.
URL
String
public
The full filepath including the file itself.
useTagLoader
Boolean
protected
If this file is using tag loading instead of the XHR method. Only used by extended classes