Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-18-2008, 06:43 PM   #1
animatorgeek
Flash Character Animator
 
Join Date: Jun 2006
Posts: 40
Default addDataToSelection problems

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:

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.
animatorgeek is offline   Reply With Quote
Old 01-18-2008, 06:50 PM   #2
animatorgeek
Flash Character Animator
 
Join Date: Jun 2006
Posts: 40
Default

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:

Code:
// change this to whatever frame number is being assigned (should be same as filename)
var FRAME_NUMBER = 1;

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
//fl.trace(current_time);

// 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;
}
else
{	
	// get ones place of the current frame number
	var new_frame = (fl.getDocumentDOM().getElementProperty('firstFrame') + 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_NAME, "integer", current_time);
It makes it through the whole command but chokes on that last line with the error mentioned above.
animatorgeek is offline   Reply With Quote
Old 01-18-2008, 07:27 PM   #3
animatorgeek
Flash Character Animator
 
Join Date: Jun 2006
Posts: 40
Default

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?
animatorgeek is offline   Reply With Quote
Old 01-18-2008, 08:43 PM   #4
animatorgeek
Flash Character Animator
 
Join Date: Jun 2006
Posts: 40
Default

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....
animatorgeek is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Major Problems with Depth and Components Veleek Components 15 01-16-2008 04:31 PM
2 scrollpane problems miguel_sanchez Components 0 11-29-2005 11:55 PM
Any one heard of problems with the flash player 7.0.14? needMoreCowBell Other Flash General Questions 1 10-22-2004 09:58 PM
levels, linkage of audio, and load movie problems to a specfic frame problems ooolie ActionScript 1.0 (and below) 0 12-05-2002 07:54 PM
dynamic swf from text problems! loaded ActionScript 1.0 (and below) 0 12-22-2001 11:06 AM


All times are GMT. The time now is 12:25 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.