View Full Version : dynamic buttons to open MC in specific position
I am using XML to dynamically create navigation. On rolling over the buttons in navigation, there is a movieclip that spawns for each button. I want the movieclip to move over each button but presently it stays in one spot and the text changes per that button. How can I move the movieclip based on what button I am on? Hopefully someone can discern from my code how to help me. I am not able to post an FLA.
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
if (ok) {
allData = this.firstChild.childNodes;
for (i=0; i<allData.length; i++) {
newBut = _root.attachMovie('butTemp', 'but'+i, i);
newBut._y = 438;
newBut._x = 45+(i*147)+50;
newBut.but_txt.text = allData[i].attributes.text;
newBut.heading = allData[i].firstChild.firstChild;
newBut.details = allData[i].firstChild.nextSibling.firstChild;
newBut.onRollOver = function() {
detailsBox = _root.attachMovie('detailsBox', 'detail'+i, i);
detailsBox._y = 234;
detailsBox._x = i*1;
detailsBox.project_text.heading_txt.text = this.heading;
detailsBox.project_text.details_txt.text = this.details;
detailsBox.gotoAndPlay("OVER");
};
newBut.onRollOut = function() {
detailsBox.gotoAndPlay("OUT");
};
}
} else {
trace('error');
}
};
myXML.load('projects.xml');
snapple
10-31-2005, 05:48 PM
I'm not quite sure exactly what your trying to do, but i think this should help:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
if (ok) {
allData = this.firstChild.childNodes;
for (i=0; i<allData.length; i++) {
// i assume that this is the button that you want the other MovieClip to move over
newBut = _root.attachMovie('butTemp', 'but'+i, i);
newBut._y = 438;
newBut._x = 45+(i*147)+50;
newBut.but_txt.text = allData[i].attributes.text;
newBut.heading = allData[i].firstChild.firstChild;
newBut.details = allData[i].firstChild.nextSibling.firstChild;
newBut.onRollOver = function()
{
detailsBox = _root.attachMovie('detailsBox', 'detail'+i, i);
detailsBox._y = 234;
detailsBox._x = i*1;
detailsBox.project_text.heading_txt.text = this.heading;
detailsBox.project_text.details_txt.text = this.details;
detailsBox.gotoAndPlay("OVER");
};
detailsBox.onEnterFrame = function()
{
// += 2 pixels to the current _x
// += 2 pixels to the current _y
// if this._x == newBut._x and if this._y == newBut _y
// then delete this onEnterFrame
}
newBut.onRollOut = function() {
detailsBox.gotoAndPlay("OUT");
};
}
} else {
trace('error');
}
};
myXML.load('projects.xml');
Regards, snapple
Thanks for trying to make out the code, snapple. I am not sure what you are suggesting.
sophistikat
11-02-2005, 06:34 PM
I want the movieclip to move over each button when do you want this happen? when you rollover??
Yes, I want the MC to come up upon rollover.
sophistikat
11-02-2005, 07:04 PM
since you can't post your fla its going to be a hit and miss but here's my first suggestions:
1. when you test your movie check your variable (Ctrl + V) and make sure your loop allowed you to create your onRollOver function
2. because i get this alot, put play(); on your label "OVER", some of my projects needs this in order to play that label
3. add a trace for testing purposes:
newBut.onRollOver = function() {
detailsBox = _root.attachMovie('detailsBox', 'detail'+i, i);
trace("rollover works");
}
Thanks. The rollover already works but I want it to follow the button (there are 6 horizontally). I want the MC to pop up over the button I roll over. Right now it pops up in one spot.
lelales
11-02-2005, 07:18 PM
If a movieclip rolls over your button, this will disable the button, so you will want to create an invisible button one layer(or more) above your movieclip, and the actual button one layer (or more) below your movie clip. Attach all rollover and press functions to the invisible button.
detailsBox._x = i*29;
I have isolated my problem. Now my question is how do I rewrite this script so the MC doesn't spawn in the same position.
sophistikat
11-03-2005, 01:25 PM
here are a couple of suggestion then:
have the xpos in an array
// your array
var mynavYPos = [0, 29, 49, 69];
// your loop
detailsBox._x = mynavYpos[i];
or give this a try
// 29 = the starting point
// 30 = the width of your movieclip
// 10 = the spacing you want between each movieclip
detailsBox._x = 29 + ((30 + 10) * i)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.