View Full Version : addDataToSelection problems

01-18-2008, 06:43 PM
I'm having some problems when I use addDataToSelection(). I'm trying to store the current time in the selected object (a symbol instance). Here's my code:

var date_object = new Date();
var current_time = date_object.getTime(); // number of milliseconds since 1970
fl.getDocumentDOM().addDataToSelection("blah", "integer", current_time);

On the call to addDataToSelection, Flash gives me an error that says "Argument number 1 is invalid." What am I doing wrong? I'm following the prototype for the function that I've seen in several documents. It doesn't seem to matter what string I put in place of "blah" -- it always gives me the same error.

I'm using Flash 8 on Windows XP.

Thanks for any help you can give.

01-18-2008, 06:50 PM
It seems I've been able to get the function to work outside the context of the command I'm developing, so I should probably give the whole command text for context:

// change this to whatever frame number is being assigned (should be same as filename)

var MOD_VAR_NAME = "modTime";

// Get the current time
var date_object = new Date();
var current_time = date_object.getTime(); // number of milliseconds since 1970

// Get the persistent data timestamp that says when this symbol's frame was set
var mod_time = fl.getDocumentDOM().selection[0].getPersistentData(MOD_VAR_NAME);

// if mod_time is undefined, set it to 0, which wil treat it like it hasn't been modified in a long time
if(mod_time == undefined)
mod_time = 0;
fl.trace("object's old timestamp: " + mod_time);

var time_since_mod = current_time - mod_time;

// Set the instance to "single frame"
fl.getDocumentDOM().setElementProperty('loop', 'single frame');

if(time_since_mod > 2000) // if it's been more than two seconds since the last modification
new_frame = FRAME_NUMBER - 1;
// get ones place of the current frame number
var new_frame = (fl.getDocumentDOM().getElementProperty('firstFram e') + 1) % 10;
new_frame *= 10;
new_frame += FRAME_NUMBER - 1;

// Set the new start frame
fl.getDocumentDOM().setElementProperty('firstFrame ', new_frame);

// Set the persistent data with a timestamp that says when this symbol's frame was set
fl.getDocumentDOM().addDataToSelection(MOD_VAR_NAM E, "integer", current_time);

It makes it through the whole command but chokes on that last line with the error mentioned above.

01-18-2008, 07:27 PM
Quick update: if I change the last parameter I pass to addDataToSelection to be a constant integer (e.g. 20), the call works fine. Now my best bet is that it's passing the number held in the variable current_time as a float, even though I never assign it any value other than an integer. I trued using parseInt() to explicitly cast it as an integer but I still got the same error. I tried ORing it with 0 to cast it as an integer (a trick I learned elsewhere online), but still the same result.

Am I missing something? Is there some other way to pass the contents of a variable the same way as if I had passed an integer constant? Or will Ijust have to store the data as a float?

01-18-2008, 08:43 PM
Well, I've gotten it working by substituting in "double" instead of "integer".

So is "integer" only for constants? Is there no way to enter data from a variable as an integer? Not that it really matters a lot, I suppose, but I'm always interested in finding a more efficient solution....