This has taken some manipulation, but I've managed to create caption labels for each of my houses and also dynamically called the houses as buttons (this is crucial later).
So what? I'm using something from earlier, right? Not exactly. Before, I loaded the text for the caption and the button actions on each instance of the button on the stage. Not the case this time, which is exciting because this is a new leap for me. I've used my arrays to dynamically load the button names into a function. So, if I want to change what ALL the "house" buttons in my file do later... all I have to do is change the master function. This is a MAJOR step towards portability!
Here's the file so far: dynamicCaption
I'll try to deconstruct this a little here. All of this AS is in the first frame of my Flash file. Eventually, as I can compact it, the most essential parts will be left in the Flash file and the more editable values will be stored in an external AS file. Throughout the code you'll see "trace();", this is just a great way to check that functions are working and values are passing through the code.
First, these are the arrays that I'm loading for each of the following five variables. Right now, "county" and "countyButton" have the same information, minus punctuation (both forms are required in code further down). I'd like to be able to manipulate the quotes with AS but haven't been able to accomplish that yet.
var county = ["","/house1","/house2","/house3","/house4"];
var countyButton = ["",house1,house2,house3,house4];
var district = ["","NE","NW","SE","SW"];
var color = ["",0x7a287a,0x0066cc,0xff0099,0xffff00];
var county_district = ["","NE","NE","SW","SE"];
var countyButton = ["",house1,house2,house3,house4];
var district = ["","NE","NW","SE","SW"];
var color = ["",0x7a287a,0x0066cc,0xff0099,0xffff00];
var county_district = ["","NE","NE","SW","SE"];
This is the function for the caption label. I gleaned it from an online tutorial a year ago... I can explain it later. But, I do need to load this function before I can call it. Reversing this order is a big no-no that just results in failure.
captionFN = function (showCaption, captionText, bName) {
if (showCaption) {
_root.createEmptyMovieClip("hoverCaption",
this.getNextHighestDepth());
cap.desc.text = captionText;
cap._width = 10*cap.desc.text.length;
cap._alpha = 90;
//
if ((bName._width+bName.x+cap._width)>Stage.width){
xo = -2-cap._width;
yo = -17;
} else {
xo = 2;
yo = -17;
}
hoverCaption.onEnterFrame = function() {
cap._x = _root._xmouse+xo;
cap._y = _root._ymouse+yo;
cap._visible = true;
};
} else {
delete hoverCaption.onEnterFrame;
cap._visible = false;
}
};
if (showCaption) {
_root.createEmptyMovieClip("hoverCaption",
this.getNextHighestDepth());
cap.desc.text = captionText;
cap._width = 10*cap.desc.text.length;
cap._alpha = 90;
//
if ((bName._width+bName.x+cap._width)>Stage.width){
xo = -2-cap._width;
yo = -17;
} else {
xo = 2;
yo = -17;
}
hoverCaption.onEnterFrame = function() {
cap._x = _root._xmouse+xo;
cap._y = _root._ymouse+yo;
cap._visible = true;
};
} else {
delete hoverCaption.onEnterFrame;
cap._visible = false;
}
};
This is a nested loop that assigns names to each of the MCs and then assigns color based on the MCs corresponding district. The variable in the square brackets pulls the appropriate value from the relevant array. (Say what? Ask me more if you want to know.)
var p = 0;
while (p<county.length) {
var q = 0;
while (q<district.length) {
if (county_district[p] == district[q]) {
county_color=color[q];
set_county_color = new Color(county[p]);
set_county_color.setRGB(county_color);
// trace (district[q]);
}
q++;
}
// trace (county[p]);
p++;
}
while (p<county.length) {
var q = 0;
while (q<district.length) {
if (county_district[p] == district[q]) {
county_color=color[q];
set_county_color = new Color(county[p]);
set_county_color.setRGB(county_color);
// trace (district[q]);
}
q++;
}
// trace (county[p]);
p++;
}
This is my test for loading the caption label per MC. It isn't quite working because it's just loading the last value for all of the houses. I think I experienced this problem earlier and need to include it in the loop above. Aside from that, I've used a new method in this section to load the caption text by dynamically manipulating data in the county string (var countyName).
var r = 0;
while (r<county.length) {countyName = county[r].substring(1,county[r].length);
trace (countyName);
countyButton[r].onRollOver = function() {
captionFN(true,countyName,this);
this.onRollOut = function() {
captionFN(false);
};
};
r++;
}
stop();
while (r<county.length) {countyName = county[r].substring(1,county[r].length);
trace (countyName);
countyButton[r].onRollOver = function() {
captionFN(true,countyName,this);
this.onRollOut = function() {
captionFN(false);
};
};
r++;
}
stop();
Fixing the caption labels
It looks like I need to add some sort of check so the AS knows to apply which caption value to which MC. I'll have to play with this a little to figure it out.
This is much more complicated than I thought. It looks like the code isn't creating a permanent caption associated with the particular MC. I think I may need to write something that duplicates and creates a new instance of the caption MC. That way, every county MC can have it's very own relative caption MC.
This description should help me remember what I'm trying to accomplish when I start combing my coding books.
Later...
This is just not coming together today. I've made some progress, duplicating the caption instance (here: dynamicCaption2) but I can't figure out how to get the dynamic clip's name into the caption function, it just won't go.
The MC duplication code is pretty simple. My caption MC is called "cap", for every duplication this should add a number to "cap" (cap1, cap2, etc.) and position the new clip about 20 pixels below the previous one.
cap.duplicateMovieClip("cap",p,{_y:p*20});
I'm going to have to walk away from this for now. Maybe something new will happen in a few days.
I'll work on the map later. I think there's a better version of the graphics at work. No point in turning all those counties into MCs if I'm going to need an updated file.

0 comments:
Post a Comment