PDA

View Full Version : return of variable and "as" file


flashdudette
01-31-2003, 04:07 PM
I have a question concerning returning values.
I have a as file named ManualId.as that is called in the first frame of serveral swf files with:

#include ("ManualId.as")


In the Manual.as file, there is the code:

// set contentId for the chapter.
function setContentId () {
prefix = "pit-"; // prefix corresponding to a specific manual
var contentId = prefix + cName;
}


Then in each chapter I have the code:

cName = "Nameofchapterhere";

But when if do a trace with

trace(contentId);

the contentId is not returned (just the cName, in this example Nameofchapterhere). It is important because we check the completion of the manual with an asp file that calls for the variable contentId.

How can I be sure that the contentId is filled with both the prefix and the cName variables?

flashdudette
01-31-2003, 04:08 PM
Oops if forgot I also have the code:
setContentId();
after the cName line in preceeding posting.

tg
01-31-2003, 07:52 PM
i think some folks here will disagree with me on this, but thats ok. the use of 'var' to help define the scope of the variable is a very good id, but in this case, it is creating a problem for you.

when you use the key word var to create a variable, it also designates the scope of that variable, so when you use the key word 'var' inside your function setContentId, it sets the scope of contentID to that function, so when flash leaves the function the variable is wiped out.

so the solution is to 1: remove the key word 'var' this will automatically give the scope to the main timeline of the current object. or 2: define your code 'var setContentId;' outside of your function.

either one should get it working for you.

flashdudette
02-03-2003, 11:08 AM
Thanks so much. It works now. Your explanation was very enlightning about the scope of variables. I appreciate. :D