-
[resolved] setting RollOver fns on dynamic MCs, within a loop
Something is amiss.
I have duplicated MCs, using loaded data and a loop. When the "spot" in the MC is rolled over, two text boxes appear. They vanish on rollout. Well, that's the idea.
It works if I do the following script minus the loop... with just say, i=1. But when I loop it, the "spots" in the different MCs don't make visible their own text boxes... they all trigger the same one: the last one. (Actually, they attempt to trigger one after the last one, if there were another. I had to mess around a lot before I figured that much out. That's why "(i-1)" is there instead of "i", so I could see what was happening.)
I assume I can't set this up this way then. How would I achieve the same effect? Thanks for any ideas...
Code:
varReceiver = new LoadVars();
varReceiver.load("fetchmapdata.php");
varReceiver.onLoad = function(){
var numspotsVar = this.numspots;
for (var i = 0; i < numspotsVar; i++) {
duplicateMovieClip("textbox", "textbox"+i, i);
_root["textbox"+i]._x = this["xx"+i];
_root["textbox"+i]._y = this["yy"+i];
_root["textbox"+i].DyText.text = this["textVar"+i];
_root["textbox"+i].DateText.text = this["dateVar"+i];
_root["textbox"+i].DyText.autoSize = "center";
_root["textbox"+i].DyText.background = true;
_root["textbox"+i].DyText.backgroundColor = 0xaaccdd;
_root["textbox"+i].DyText.wordWrap = true;
_root["textbox"+i].DyText._visible = false;
_root["textbox"+i].DateText.background = true;
_root["textbox"+i].DateText.backgroundColor = 0xaaccdd;
_root["textbox"+i].DateText._visible = false;
_root["textbox"+i].spot.onRollOver = function () {
_root["textbox"+(i-1)].DyText._visible = true;
_root["textbox"+(i-1)].DateText._visible = true;
}
_root["textbox"+i].spot.onRollOut = function () {
_root["textbox"+(i-1)].DyText._visible = false;
_root["textbox"+(i-1)].DateText._visible = false;
}
}
}
Last edited by hermie; 08-07-2004 at 01:18 PM.
-
Flash Student
hi,
Try this and see if it works:
Code:
varReceiver = new LoadVars();
varReceiver.load("fetchmapdata.php");
varReceiver.onLoad = function() {
var numspotsVar = this.numspots;
for (var i = 0; i<numspotsVar; i++) {
duplicateMovieClip("textbox", "textbox"+i, i);
this["textbox"+i]._x = this["xx"+i];
this["textbox"+i]._y = this["yy"+i];
this["textbox"+i].DyText.text = this["textVar"+i];
this["textbox"+i].DateText.text = this["dateVar"+i];
this["textbox"+i].DyText.autoSize = "center";
this["textbox"+i].DyText.background = true;
this["textbox"+i].DyText.backgroundColor = 0xaaccdd;
this["textbox"+i].DyText.wordWrap = true;
this["textbox"+i].DyText._visible = false;
this["textbox"+i].DateText.background = true;
this["textbox"+i].DateText.backgroundColor = 0xaaccdd;
this["textbox"+i].DateText._visible = false;
this["textbox"+i].spot.onRollOver = function() {
this["textbox"+(i-1)].DyText._visible = true;
this["textbox"+(i-1)].DateText._visible = true;
};
this["textbox"+i].spot.onRollOut = function() {
this["textbox"+(i-1)].DyText._visible = false;
this["textbox"+(i-1)].DateText._visible = false;
};
}
};
Cheers
Rabid Lemming
I will wait for death with a smile and a big stick
-
Senior Member
As you guessed your problem is with i, as when one of your rollovers is executed the loop has finished and i is numspotsVar.
You need a dynamic reference to each MCs number, or in your case, just this
code:
_root["textbox"+i].spot.onRollOver = function() {
this._parent.DyText._visible = true;
this._parent.DateText._visible = true;
};
_root["textbox"+i].spot.onRollOut = function() {
this._parent.DyText._visible = false;
this._parent.DateText._visible = false;
};
as 'this' within the function refers to each MCs spot, then use _parent to go up one to the MC itself.
-
Excellent! Thanks for the clear explanation too... now I've got a handle on what's going on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|