PDA

View Full Version : Need help adding movieclip var values


masteroleary
06-13-2005, 09:57 PM
:confused:
I need help! I am trying to add the values of two MovieClip variables

The purpose of this function is to check if a section is loaded. If it isnt then it will load it, if it is then it will send it to the nextHighestDepth. The yesNo array object stores Boolean values which allow the function to determine if the section has been loaded previously. Var x stores the static path which needs to be combined to the variable mcTarg which is passed to the function.
The problem is that what I currently have loads the target file (fileTarg) into the root, replacing the movie mainframe.My only guess is that when adding the values of the two movie clip variables the dot (.) that seperates them is not being added intuitively.

var yesNo:Array = new Array();
yesNo["holdBio_mc"] = false;

function loadIt(mcTarg:MovieClip, fileTarg:String) {
var x:MovieClip = _root.holder_mc;
var localTarg:MovieClip = _root.holder_mc + '.' + mcTarg;

if (yesNo[mcTarg] == true) {
localTarg.swapDepths(_root.getNextHighestDepth());

} else {
_root.holder_mc.createEmptyMovieClip(mcTarg, this.getNextHighestDepth());
mcLoader.loadClip(fileTarg, localTarg);
yesNo["holdBio_mc"] = true;
trace(yesNo["holdBio_mc"]);
}
}

deadbeat
06-13-2005, 10:00 PM
Try:

var localTarg:MovieClip = _root.holder_mc[mcTarg];

K.

masteroleary
06-13-2005, 11:35 PM
Obviously I am missing some actionscript fundamentals. Yours solution works perfectly. Now I am having a scope issue (i think). I set the value of yesNo["holdBio_mc"] outside the function. What I want the function to do is check to see if (yesNo[mcTarg] == true){ then trace("if);

else (which i assume must be false) then trace("else"); and then set the yesNo["holdBio_mc"] to true

what is happening is that i test it and it traces false else, then i click the button again and it says true else. I want it to trace false else, true if

i dont understand why it keeps running ELSE when i changed it to true. Perhaps my if statement is incorrectly written?

var yesNo:Array = new Array();
yesNo["holdBio_mc"] = false;

function loadIt(mcTarg:MovieClip, fileTarg:String) {

var localTarg:MovieClip = _root.holder_mc[mcTarg];
trace(yesNo["holdBio_mc"]);

if (yesNo[mcTarg] == true) {
trace("if");
} else {
trace("else");
yesNo["holdBio_mc"] = true;
}
}

deadbeat
06-13-2005, 11:56 PM
Try:

if (yesNo[mcTarg.toString()] == true) {

K.

masteroleary
06-14-2005, 12:29 AM
If this is the code you suggested I am sorry to say that it continues to trace "else". :( Argg. I really appreciate the help you have given me so far by the way.

*I just discovered that by replacing mcTarg with "holdBio_mc" (the value that is passed through the var mcTarg) it works. Perhaps the syntax is incorrect?

var yesNo:Array = new Array();
yesNo["holdBio_mc"] = false;
function loadIt(mcTarg:MovieClip, fileTarg:String) {
var localTarg:MovieClip = _root.holder_mc[mcTarg];
trace(yesNo["holdBio_mc"]);
if (yesNo[mcTarg.toString()] == true) {
trace("if");
} else {
trace("else");
yesNo["holdBio_mc"] = true;
}
}

deadbeat
06-14-2005, 12:49 AM
Well, in your function, you are using mcTarg as a movieclip reference, and you really need to use it as a string...so you might need to pull the _name property first...

Try adding a couple of traces to the function and see what is being passed in:


var yesNo:Array = new Array();

yesNo["holdBio_mc"] = false;

function loadIt(mcTarg:MovieClip, fileTarg:String) {

var localTarg:MovieClip = _root.holder_mc[mcTarg];

trace(mcTarg);
trace(mcTarg._name);

if (yesNo[mcTarg._name] == true) {
trace("if");
}
else {
trace("else");
yesNo["holdBio_mc"] = true;
}
}


K.

masteroleary
06-14-2005, 12:59 AM
Thanks man. I just got it to work! I really appreciate your help!