I actually wrote a sniplet that allows to get all the keys properties (including interpolation types, etc) to a JavaScript Object Notation (JSON). Please read through. the try..catch have to be used because some of them just threw exceptions instead. Weird, huh?
Code: Select all
/**
* get all of the keys in a property, and store as a variable (this.keys)
*/
this.getKeys = function( )
{
var property = this.property ;
var keys = [ ] ;
var i , k ;
for ( i = 0 ; i < this.property.numKeys ; i ++ )
{
k = i + 1 ;
keys[ i ] =
{
key : k
, value : property.keyValue( k )
, time : property.keyTime( k )
, interpolationType : [ property.keyInInterpolationType( k ) , property.keyOutInterpolationType( k ) ]
// , spatialTangents : [ property.keyInSpatialTangent( k ) , property.keyOutSpatialTangent( k ) ]
, temoralEase : [ property.keyInTemporalEase( k ) , property.keyOutTemporalEase( k ) ]
, temporalContinuous : property.keyTemporalContinuous( k )
, temporalAutoBezier : property.keyTemporalAutoBezier( k )
// , roving : property.keyRoving( k )
, selected : property.keySelected( k )
} ;
try{ keys[i]['spatialTangents'] = [ property.keyInSpatialTangent( k ) , property.keyOutSpatialTangent( k ) ] ; } catch( err ) { }
try{ keys[i]['roving'] = property.keyRoving( k ) ; } catch( err ) { }
}
this.keys = keys ;
this.settings =
{
propertyValueType : 'propertyValueType'
, hasMin : 'hasMin'
, hasMax : 'hasMax'
, minValue : 'minValue'
, maxValue : 'maxValue'
, isSpatial : 'isSpatial'
, canVaryOverTime : 'canVaryOverTime'
, isTimeVarying : 'isTimeVarying'
, unitsText : 'unitsTime'
, expressionEnabled : 'expressionEnabled'
, expression : 'expression'
, canSetExpression : 'canSetExpression'
, expressionError : 'expressionError'
, keyframeInterpolationType : 'keyframeInterpolationType'
} ;
for ( i in this.settings )
{
try { this.settings[i] = property[this.settings[i]] ; } catch(err) { this.settings[i] = undefined ;}
}
return this ;
}
I wrote another function to do setKeys, but it has a different purpose than what you need, so it's done a bit differently and a bit more complicated, but just reverse this function and you can get what you need perfectly.
Edit: setKey is as follows:
Code: Select all
/**
* @function setKey -- set a single key
* @param newKey (object) -- current, new key to be set
* @param keyIndex -- the current key index on newKey
* @param names -- names -- an array of the name list; undefined to use all.
*/
this.setKey = function( newKey , keyIndex , names )
{
var i , method , name ;
var index = null ;
if ( names == undefined )
{
names =
[ "value"
, "interpolationType"
, "spatialTangents"
, "temporalEase"
, "temporalContinuous"
, "spatialContinuous"
, "roving"
, "selected"
, "temporalAutoBezier"
, "spatialAutoBezier" ] ;
}
if ( newKey.time != undefined )
{
index = this.property.addKey( newKey.time ) ;
}
for ( i = 0 ; i < names.length ; i ++ )
{
name = names[i] ;
method = "set" + name[0].toUpperCase( ) + name.substring( 1 ) + "AtKey" ;
a = newKey[name] == undefined ? this.keys[keyIndex-1][name] : newKey[name] ;
if ( a == undefined ) { continue ; }
if ( ( name != 'value' ) && ( a instanceof Array ) )
{
try{ this.property[method]( index != null ? index : keyIndex , a[0] , a[1] ) } catch( err ) { }
}
else
{
this.property[method]( index != null ? index : keyIndex , a ) ;
// try{ this.property[method]( index != null ? index : keyIndex , a ) ; } catch( err ) { throw( "Error: " + method ) }
}
}
return this ;
}